Make WordPress Core

Ticket #26959: 26959-11.patch

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

     
    336336                        if ( isView( view.previousSibling ) ) {
    337337                                select( view.previousSibling );
    338338                        // Handle case where view is the first node
    339                         } else if ( view.previousSibling === null ) {
     339                        } else if ( ! view.previousSibling ) {
    340340                                padNode = createPadNode();
    341341                                body.insertBefore( padNode, body.firstChild );
    342342                                editor.selection.setCursorLocation( body.firstChild, 0 );
     
    351351                        if ( isView( view.nextSibling ) ) {
    352352                                select( view.nextSibling );
    353353                        // Handle case were the view is that last node
    354                         } else if ( view.nextSibling === null ) {
     354                        } else if ( ! view.nextSibling ) {
    355355                                padNode = createPadNode();
    356356                                body.appendChild( padNode );
    357357                                editor.selection.setCursorLocation( body.lastChild, 0 );
    358358                        // Handle default case where the next node is a non-wpview
    359359                        } else {
    360                                 editor.selection.setCursorLocation( view.nextSibling.firstChild, 0 );
     360                                editor.selection.setCursorLocation( view.nextSibling, 0 );
    361361                        }
    362362                } else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
    363363                        // If delete or backspace is pressed, delete the view.
     
    370370        // Select and deselect views when arrow keys are used to navigate the content of the editor.
    371371        editor.on( 'keydown', function( event ) {
    372372                var keyCode = event.keyCode,
     373                        dom = editor.dom,
    373374                        range = editor.selection.getRng(),
     375                        startNode = range.startContainer,
    374376                        body = editor.getBody(),
    375                         node;
     377                        node, container;
    376378
    377                 if ( ! range.collapsed || event.metaKey || event.ctrlKey ) {
     379                if ( ! startNode || startNode === body || event.metaKey || event.ctrlKey ) {
    378380                        return;
    379381                }
    380382
    381                 if ( keyCode === VK.LEFT || keyCode === VK.UP ) {
    382                         node = range.startContainer.parentNode === body ? range.startContainer : range.startContainer.parentNode;
    383                         // The caret is directly after a wpview
    384                         if ( range.startOffset === 0 && isView( node.previousSibling ) ) {
     383                if ( keyCode === VK.UP || keyCode === VK.LEFT ) {
     384                        if ( keyCode === VK.LEFT && ( ! range.collapsed || range.startOffset !== 0 ) ) {
     385                                // Not at the beginning of the current range
     386                                return;
     387                        }
     388
     389                        node = dom.getParent( startNode, dom.isBlock );
     390
     391                        if ( ! node ) {
     392                                return;
     393                        }
     394
     395                        while ( node && node.parentNode !== body ) {
     396                                if ( node.previousSibling ) {
     397                                        // The caret will be in another element
     398                                        return;
     399                                }
     400
     401                                node = node.parentNode;
     402                        }
     403
     404                        if ( isView( node.previousSibling ) ) {
    385405                                select( node.previousSibling );
    386406                                event.preventDefault();
    387407                        }
    388                 } else if ( keyCode === VK.RIGHT || keyCode === VK.DOWN ) {
    389                         node = range.startContainer.parentNode === body ? range.startContainer : range.startContainer.parentNode;
    390                         // The caret is directly before a wpview
    391                         if ( ( ( range.startOffset === 0 && ! range.endContainer.length ) || ( range.startOffset === range.endContainer.length ) ) &&
    392                                         isView( node.nextSibling ) ) {
     408                } else if ( keyCode === VK.DOWN || keyCode === VK.RIGHT ) {
     409                        node = dom.getParent( startNode, dom.isBlock );
     410
     411                        if ( ! node ) {
     412                                return;
     413                        }
     414
     415                        if ( keyCode === VK.RIGHT ) {
     416                                container = range.endContainer;
     417
     418                                if ( ! range.collapsed || ( range.startOffset === 0 && container.length ) ||
     419                                        container.nextSibling ||
     420                                        ( container.nodeType === 3 && range.startOffset !== container.length ) ) { // Not at the end of the current range
     421
     422                                        return;
     423                                }
     424
     425                                // In a child element
     426                                while ( container && container !== node && container !== body ) {
     427                                        if ( container.nextSibling ) {
     428                                                return;
     429                                        }
     430                                        container = container.parentNode;
     431                                }
     432                        }
     433
     434                        while ( node && node.parentNode !== body ) {
     435                                if ( node.nextSibling ) {
     436                                        // The caret will be in another element
     437                                        return;
     438                                }
     439
     440                                node = node.parentNode;
     441                        }
     442
     443                        if ( isView( node.nextSibling ) ) {
    393444                                select( node.nextSibling );
    394445                                event.preventDefault();
    395446                        }