Ticket #6629: 6629_3.patch

File 6629_3.patch, 3.3 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/wysiwygarea/plugin.js

     
    1010
    1111(function()
    1212{
    13         // List of elements in which has no way to move editing focus outside.
    14         var nonExitableElementNames = { table:1,pre:1 };
    15 
    1613        // Matching an empty paragraph at the end of document.
    17         var emptyParagraphRegexp = /(^|<body\b[^>]*>)\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi;
     14        var emptyParagraphRegexp = /(^|<body\b[^>]*>)\s*<(p|div|address|h\d|center|pre)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\2>)?\s*(?=$|<\/body>)/gi;
    1815
    1916        var notWhitespaceEval = CKEDITOR.dom.walker.whitespaces( true );
    2017
    21         // Elements that could have empty new line around, including table, pre-formatted block, hr, page-break. (#6554)
    22         function nonExitable( element )
     18        // Elements that could blink the cursor anchoring beside it, like hr, page-break. (#6554)
     19        function nonEditable( element )
    2320        {
    24                 return ( element.getName() in nonExitableElementNames )
    25                                 || element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];
     21                return element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];
    2622        }
    2723
    2824
     
    409405                                var element = fixedBlock.getNext( isNotWhitespace );
    410406                                if ( element &&
    411407                                         element.type == CKEDITOR.NODE_ELEMENT &&
    412                                          !nonExitable( element ) )
     408                                         !nonEditable( element ) )
    413409                                {
    414410                                        range.moveToElementEditStart( element );
    415411                                        fixedBlock.remove();
     
    419415                                        element = fixedBlock.getPrevious( isNotWhitespace );
    420416                                        if ( element &&
    421417                                                 element.type == CKEDITOR.NODE_ELEMENT &&
    422                                                  !nonExitable( element ) )
     418                                                 !nonEditable( element ) )
    423419                                        {
    424420                                                range.moveToElementEditEnd( element );
    425421                                                fixedBlock.remove();
     
    432428                        evt.cancel();
    433429                }
    434430
    435                 // All browsers are incapable to moving cursor out of certain non-exitable
    436                 // blocks (e.g. table, list, pre) at the end of document, make this happen by
    437                 // place a bogus node there, which would be later removed by dataprocessor.
    438                 var walkerRange = new CKEDITOR.dom.range( editor.document ),
    439                         walker = new CKEDITOR.dom.walker( walkerRange );
    440                 walkerRange.selectNodeContents( body );
    441                 walker.evaluator = function( node )
     431                // Browsers are incapable of moving cursor out of certain block elements (e.g. table, div, pre)
     432                // at the end of document, makes it unable to continue adding content, we have to make this
     433                // easier by opening an new empty paragraph.
     434                var testRange = new CKEDITOR.dom.range( editor.document );
     435                testRange.moveToElementEditEnd( editor.document.getBody() );
     436                var testPath = new CKEDITOR.dom.elementPath( testRange.startContainer );
     437                if ( !testPath.blockLimit.is( 'body') )
    442438                {
    443                         return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
    444                 };
    445                 walker.guard = function( node, isMoveout )
    446                 {
    447                         return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
    448                 };
    449 
    450                 if ( walker.previous() )
    451                 {
    452439                        editor.fire( 'updateSnapshot' );
    453440                        restoreDirty( editor );
    454441                        CKEDITOR.env.ie && restoreSelection( selection );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy