Ticket #4898: 4898.patch

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

     
    170170                }
    171171        }
    172172
     173        var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
     174
    173175        /**
    174176         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent
    175177         *  non-exitable-block by padding extra br.(#3189)
     
    211213                                var previousElement = fixedBlock.getPrevious( isNotWhitespace ),
    212214                                        nextElement = fixedBlock.getNext( isNotWhitespace );
    213215
    214 
    215216                                if ( previousElement && previousElement.getName
    216217                                         && !( previousElement.getName() in nonExitableElementNames )
    217218                                         && range.moveToElementEditStart( previousElement )
     
    222223                                        fixedBlock.remove();
    223224                                }
    224225                        }
    225 
    226                         range.select();
    227                         // Notify non-IE that selection has changed.
    228                         if ( !CKEDITOR.env.ie )
    229                                 editor.selectionChange();
    230226                }
    231227
    232228                // All browsers are incapable to moving cursor out of certain non-exitable
    233229                // blocks (e.g. table, list, pre) at the end of document, make this happen by
    234230                // place a bogus node there, which would be later removed by dataprocessor.
    235                 var lastNode = body.getLast( CKEDITOR.dom.walker.whitespaces( true ) );
    236                 if ( lastNode && lastNode.getName && ( lastNode.getName() in nonExitableElementNames ) )
     231                var walkerRange = new CKEDITOR.dom.range( editor.document ),
     232                        walker = new CKEDITOR.dom.walker( walkerRange );
     233                walkerRange.selectNodeContents( body );
     234                walker.evaluator = function( node )
    237235                {
     236                        return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in nonExitableElementNames );
     237                };
     238                walker.guard = function( node, isMoveout )
     239                {
     240                        return !( ( node.type == CKEDITOR.NODE_TEXT && isNotWhitespace( node ) ) || isMoveout );
     241                };
     242
     243                if ( walker.previous() )
     244                {
    238245                        restoreDirty( editor );
    239246                        CKEDITOR.env.ie && restoreSelection( selection );
    240247
    241                         if ( !CKEDITOR.env.ie )
    242                                 body.appendBogus();
     248                        var paddingBlock;
     249                        if ( enterMode != CKEDITOR.ENTER_BR )
     250                                paddingBlock = body.append( new CKEDITOR.dom.element( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) );
    243251                        else
    244                                 body.append( editor.document.createText( '\xa0' ) );
     252                                paddingBlock = body;
     253
     254                        if ( !CKEDITOR.env.ie )
     255                                paddingBlock.appendBogus();
    245256                }
     257               
     258                range.select();
     259                editor.selectionChange();
    246260        }
    247261
    248262        CKEDITOR.plugins.add( 'wysiwygarea',
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy