Ticket #4543: 4543_2.patch

File 4543_2.patch, 3.2 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/wysiwygarea/plugin.js

     
    1515         */
    1616        var nonExitableElementNames = { table:1,pre:1 };
    1717        // Matching an empty paragraph at the end of document.
    18         var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)\s*(:?<\/\1>)?\s*$/gi;
     18        var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;)?\s*(:?<\/\1>)?\s*$/gi;
    1919
    2020        function onInsertHtml( evt )
    2121        {
     
    175175                         && !path.block )
    176176                {
    177177                        restoreDirty( editor );
    178                         var bms = selection.createBookmarks(),
    179                                 fixedBlock = range.fixBlock( true,
     178                        var fixedBlock = range.fixBlock( true,
    180179                                        editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );
    181180
    182181                        // For IE, we should remove any filler node which was introduced before.
     
    186185                                first && isNbsp( first ) && first.remove();
    187186                        }
    188187
    189                         selection.selectBookmarks( bms );
     188                        // If the fixed block is blank and already followed by a exitable
     189                        // block, we should revert the fix. (#3684)
     190                        if( fixedBlock.getOuterHtml().match( emptyParagraphRegexp ) )
     191                        {
     192                                var previousElement = fixedBlock.getPrevious( isNotWhitespace ),
     193                                        nextElement = fixedBlock.getNext( isNotWhitespace );
    190194
    191                         // If the fixed block is blank and is already followed by a exitable
    192                         // block, we should drop it and move to the exist block(#3684).
    193                         var children = fixedBlock.getChildren(),
    194                                 count = children.count(),
    195                                 firstChild,
    196                                 previousElement = fixedBlock.getPrevious( isNotWhitespace ),
    197                                 nextElement = fixedBlock.getNext( isNotWhitespace ),
    198                                 enterBlock;
    199                         if ( previousElement && previousElement.getName
    200                                  && !( previousElement.getName() in nonExitableElementNames ) )
    201                                 enterBlock = previousElement;
    202                         else if ( nextElement && nextElement.getName
    203                                           && !( nextElement.getName() in nonExitableElementNames ) )
    204                                 enterBlock = nextElement;
    205195
    206                         // Not all blocks are editable, e.g. <hr />, further checking it.(#3994)
    207                         if( ( !count
    208                                   || ( firstChild = children.getItem( 0 ) ) && firstChild.is && firstChild.is( 'br' ) )
    209                                 && enterBlock
    210                                 && range.moveToElementEditStart( enterBlock ) )
    211                         {
    212                                 fixedBlock.remove();
    213                                 range.select();
    214                         }
    215                 }
     196                                if ( previousElement && previousElement.getName
     197                                         && !( previousElement.getName() in nonExitableElementNames )
     198                                         && range.moveToElementEditStart( previousElement )
     199                                         || nextElement && nextElement.getName
     200                                           && !( nextElement.getName() in nonExitableElementNames )
     201                                           && range.moveToElementEditStart( nextElement ) )
     202                                {
     203                                        fixedBlock.remove();
     204                                }
     205                        }
    216206
     207                        range.select();
     208                        // Notify non-IE that selection has changed.
     209                        if( !CKEDITOR.env.ie )
     210                                editor.selectionChange();
     211                }
     212
    217213                // All browsers are incapable to moving cursor out of certain non-exitable
    218214                // blocks (e.g. table, list, pre) at the end of document, make this happen by
    219215                // place a bogus node there, which would be later removed by dataprocessor. 
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy