Make WordPress Core

Ticket #26959: 26959-07.patch

File 26959-07.patch, 3.8 KB (added by gcorne, 11 years ago)
  • src/wp-includes/js/tinymce/plugins/wpview/plugin.js

    diff --git src/wp-includes/js/tinymce/plugins/wpview/plugin.js src/wp-includes/js/tinymce/plugins/wpview/plugin.js
    index 48775f9..e284a21 100644
    tinymce.PluginManager.add( 'wpview', function( editor ) { 
    8686                editor.dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );
    8787                editor.dom.bind( selected, 'beforedeactivate focusin focusout', _stop );
    8888
     89                // Make sure that the editor is focused.
     90                // It is possible that the editor is not focused when the mouse event fires
     91                // without focus, the selection will not work properly.
     92                editor.getBody().focus();
     93
    8994                // select the hidden div
    9095                editor.selection.select( clipboard, true );
    9196        }
    tinymce.PluginManager.add( 'wpview', function( editor ) { 
    156161                                editor.selection.setCursorLocation( padNode, 0 );
    157162                        }
    158163                }
    159 
    160         //      refreshEmptyContentNode();
    161164        });
    162165
    163166        // Detect mouse down events that are adjacent to a view when a view is the first view or the last view
    tinymce.PluginManager.add( 'wpview', function( editor ) { 
    188191                        }
    189192
    190193                        if ( padNode ) {
     194                                // Make sure that a selected view is deselected so that focus and selection are handled properly
     195                                deselect();
     196                                editor.getBody().focus();
    191197                                editor.selection.setCursorLocation( padNode, 0 );
    192198                        }
    193199                }
    tinymce.PluginManager.add( 'wpview', function( editor ) { 
    298304
    299305        editor.on( 'keydown', function( event ) {
    300306                var keyCode = event.keyCode,
    301                         view;
     307                        body = editor.getBody(),
     308                        view, padNode;
    302309
    303310                // If a view isn't selected, let the event go on its merry way.
    304311                if ( ! selected ) {
    tinymce.PluginManager.add( 'wpview', function( editor ) { 
    323330                        return;
    324331                }
    325332
     333                if ( keyCode === VK.LEFT || keyCode === VK.UP ) {
     334                        deselect();
     335                        if ( isView( view.previousSibling ) ) {
     336                                select( view.previousSibling );
     337                        } else if ( view.previousSibling === null ) {
     338                                padNode = createPadNode();
     339                                body.insertBefore( padNode, body.firstChild );
     340                                editor.selection.setCursorLocation( body.firstChild, 0 );
     341                        } else {
     342                                editor.selection.select( view.previousSibling, true );
     343                                editor.selection.collapse();
     344                        }
     345                }
     346
     347                if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) {
     348                        deselect();
     349                        if ( isView( view.nextSibling ) ) {
     350                                select( view.nextSibling );
     351                        } else if ( view.nextSibling === null ) {
     352                                padNode = createPadNode();
     353                                body.appendChild( padNode );
     354                                editor.selection.setCursorLocation( body.lastChild, 0 );
     355
     356                        } else {
     357                                editor.selection.setCursorLocation( view.nextSibling.firstChild, 0 );
     358                        }
     359                }
     360
    326361                // If delete or backspace is pressed, delete the view.
    327362                if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
    328363                        editor.dom.remove( selected );
    tinymce.PluginManager.add( 'wpview', function( editor ) { 
    331366                event.preventDefault();
    332367        });
    333368
     369        // Select and deselect views when arrow keys are used to navigate the content of the editor.
     370        editor.on( 'keydown', function( event ) {
     371                var keyCode = event.keyCode,
     372                        range = editor.selection.getRng();
     373
     374                if ( range.collapsed !== true ) {
     375                        return;
     376                }
     377
     378                if ( keyCode === VK.LEFT || keyCode === VK.UP ) {
     379                        if ( range.startOffset === 0 && isView( range.startContainer.parentNode.previousSibling ) ) {
     380                                select( range.startContainer.parentNode.previousSibling );
     381                                event.preventDefault();
     382                                return;
     383                        }
     384
     385                } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) {
     386                        if ( range.startOffset === range.endContainer.length && isView( range.startContainer.parentNode.nextSibling ) ) {
     387                                select( range.endContainer.parentNode.nextSibling );
     388                                event.preventDefault();
     389                                return;
     390                        }
     391
     392                }
     393
     394
     395        });
     396
    334397        editor.on( 'keyup', function( event ) {
    335398                var padNode,
    336399                        keyCode = event.keyCode,