Ticket #3933: 3933_2.patch

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

     
    139139                        setTimeout( function(){ editor.resetDirty(); } );
    140140        }
    141141
     142        var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true ),
     143                isNotBookmark = CKEDITOR.dom.walker.bookmark( false, true );
     144
     145        function isNotEmpty( node )
     146        {
     147                return isNotWhitespace( node ) && isNotBookmark( node );
     148        };
     149
     150        function isNbsp( node )
     151        {
     152                return node.type == CKEDITOR.NODE_TEXT
     153                           && CKEDITOR.tools.trim( node.getText() ).match( /^(?: |\xa0)$/ );
     154        }
     155
    142156        /**
    143157         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent
    144158         *  non-exitable-block by padding extra br.(#3189)
     
    165179                                fixedBlock = range.fixBlock( true,
    166180                                        editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p'  );
    167181
    168                         // For IE, we'll be removing any bogus br ( introduce by fixing body )
    169                         // right now to prevent it introducing visual line break.
     182                        // For IE, we should remove any filler node which was introduced before.
    170183                        if ( CKEDITOR.env.ie )
    171184                        {
    172                                 var brNodeList = fixedBlock.getElementsByTag( 'br' ), brNode;
    173                                 for ( var i = 0 ; i < brNodeList.count() ; i++ )
    174                                 {
    175                                         if( ( brNode = brNodeList.getItem( i ) ) && brNode.hasAttribute( '_cke_bogus' ) )
    176                                                 brNode.remove();
    177                                 }
    178                         }
     185                                var first = fixedBlock.getFirst( isNotEmpty );
     186                                isNbsp( first ) && first.remove();
     187                        }
    179188
    180189                        selection.selectBookmarks( bms );
    181190
     
    184193                        var children = fixedBlock.getChildren(),
    185194                                count = children.count(),
    186195                                firstChild,
    187                                 whitespaceGuard = CKEDITOR.dom.walker.whitespaces( true ),
    188                                 previousElement = fixedBlock.getPrevious( whitespaceGuard ),
    189                                 nextElement = fixedBlock.getNext( whitespaceGuard ),
     196                                previousElement = fixedBlock.getPrevious( isNotWhitespace ),
     197                                nextElement = fixedBlock.getNext( isNotWhitespace ),
    190198                                enterBlock;
    191199                        if ( previousElement && previousElement.getName
    192200                                 && !( previousElement.getName() in nonExitableElementNames ) )
     
    206214                        }
    207215                }
    208216
    209                 // Inserting the padding-br before body if it's preceded by an
    210                 // unexitable block.
     217                // All browsers are incapable to moving cursor out of certain non-exitable
     218                // blocks (e.g. table, list, pre) at the end of document, make this happen by
     219                // place a bogus node there, which would be later removed by dataprocessor. 
    211220                var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );
    212221                if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )
    213222                {
    214223                        restoreDirty( editor );
    215                         var paddingBlock = editor.document.createElement(
    216                                         ( CKEDITOR.env.ie && enterMode != CKEDITOR.ENTER_BR ) ?
    217                                                 '<br _cke_bogus="true" />' : 'br' );
    218                         body.append( paddingBlock );
     224                        if( !CKEDITOR.env.ie )
     225                                body.appendBogus();
     226                        else
     227                                body.append( editor.document.createText( '\xa0' ) );
    219228                }
    220229        }
    221230
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy