Make WordPress Core

Ticket #28328: 28328.13.patch

File 28328.13.patch, 2.4 KB (added by iseulde, 11 years ago)
  • src/wp-admin/js/editor-expand.js

     
    122122                        }, 200 );
    123123                } );
    124124
     125                // Make sure the cursor is always visible.
     126                // This is not only necessary to keep the cursor between the toolbars,
     127                // but also to scroll the window when the cursor moves out of the viewport to a wpview.
     128                // Setting a buffer > 0 will prevent the browser default.
     129                // Some browsers will scroll to the middle,
     130                // others to the top/bottom of the *window* when moving the cursor out of the viewport.
    125131                editor.on( 'keyup', function() {
    126132                        var offset = getCursorOffset(),
    127133                                windowHeight = $window.height(),
     134                                buffer = 10,
    128135                                cursorTop, cursorBottom, editorTop, editorBottom;
    129136
    130137                        if ( ! offset ) {
     
    133140
    134141                        cursorTop = offset.top + editor.getContentAreaContainer().getElementsByTagName( 'iframe' )[0].getBoundingClientRect().top;
    135142                        cursorBottom = cursorTop + offset.height;
     143                        cursorTop = cursorTop - buffer;
     144                        cursorBottom = cursorBottom + buffer;
    136145                        editorTop = $adminBar.outerHeight() + $tools.outerHeight() + $visualTop.outerHeight();
    137                         editorBottom = $window.height() - $bottom.outerHeight();
     146                        editorBottom = windowHeight - $bottom.outerHeight();
    138147
    139                         if ( cursorTop < editorTop || cursorBottom > editorBottom ) {
    140                                 window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - windowHeight / 2 );
     148                        if ( cursorTop < editorTop ) {
     149                                window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop );
     150                        } else if ( cursorBottom > editorBottom ) {
     151                                window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom );
    141152                        }
    142153                } );
    143154
     
    145156                        var selection = editor.selection,
    146157                                node = selection.getNode(),
    147158                                range = selection.getRng(),
    148                                 view, clone, right, offset;
     159                                view, clone, offset;
    149160
    150161                        if ( tinymce.Env.ie && tinymce.Env.ie < 9 ) {
    151162                                return;
     
    159170                                if ( clone.startContainer.length > 1 ) {
    160171                                        if ( clone.startContainer.length > clone.endOffset ) {
    161172                                                clone.setEnd( clone.startContainer, clone.endOffset + 1 );
    162                                                 right = true;
    163173                                        } else {
    164174                                                clone.setStart( clone.startContainer, clone.endOffset - 1 );
    165175                                        }
     
    175185                        }
    176186
    177187                        if ( ! offset.height ) {
    178                                 return false;
     188                                return;
    179189                        }
    180190
    181191                        return offset;