Ticket #5402: 5402.patch

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

     
    170170                }
    171171        }
    172172
     173        function isBlankParagraph( block )
     174        {
     175                return block.getOuterHtml().match( emptyParagraphRegexp );
     176        }
     177
     178        var isNotWhitespace = CKEDITOR.dom.walker.whitespaces( true );
     179
    173180        /**
    174181         *  Auto-fixing block-less content by wrapping paragraph (#3190), prevent
    175182         *  non-exitable-block by padding extra br.(#3189)
     
    204211                                first && isNbsp( first ) && first.remove();
    205212                        }
    206213
    207                         // If the fixed block is blank and already followed by a exitable
    208                         // block, we should revert the fix. (#3684)
    209                         if ( fixedBlock.getOuterHtml().match( emptyParagraphRegexp ) )
     214                        // If the fixed block is actually blank and is already followed by an exitable blank
     215                        // block, we should revert the fix and move into the existed one. (#3684)
     216                        if ( isBlankParagraph( fixedBlock ) )
    210217                        {
    211218                                var previousElement = fixedBlock.getPrevious( isNotWhitespace ),
    212219                                        nextElement = fixedBlock.getNext( isNotWhitespace );
    213220
    214221                                if ( previousElement && previousElement.getName
    215222                                         && !( previousElement.getName() in nonExitableElementNames )
     223                                         && isBlankParagraph( previousElement )
    216224                                         && range.moveToElementEditStart( previousElement )
    217225                                         || nextElement && nextElement.getName
    218                                            && !( nextElement.getName() in nonExitableElementNames )
    219                                            && range.moveToElementEditStart( nextElement ) )
     226                                                && !( nextElement.getName() in nonExitableElementNames )
     227                                                && isBlankParagraph( nextElement )
     228                                                && range.moveToElementEditStart( nextElement ) )
    220229                                {
    221230                                        fixedBlock.remove();
    222231                                }
  • _source/plugins/enterkey/plugin.js

     
    1414                        var specialKeys = editor.specialKeys;
    1515                        specialKeys[ 13 ] = enter;
    1616                        specialKeys[ CKEDITOR.SHIFT + 13 ] = shiftEnter;
     17                        specialKeys[ CKEDITOR.CTRL + CKEDITOR.SHIFT + 13 ] = ctrlShiftEnter;
    1718                }
    1819        });
    1920
     
    281282                        range.collapse( true );
    282283
    283284                        range.select( isPre );
    284                 }
     285                },
     286
     287                /**
     288                 * If the cursor is inside a block, exit from the current block by putting the cursor after the end of it.
     289                 * @param editor
     290                 */
     291                enterExit : function( editor )
     292                {
     293                        var range = getRange( editor ),
     294                                        doc = editor.document,
     295                                        path = new CKEDITOR.dom.elementPath( range.startContainer ),
     296                                        block = path.block || path.blockLimit;
     297
     298                        if ( block )
     299                        {
     300                                var parent;
     301                                while( block && ( parent = block.getParent() )
     302                                        && !CKEDITOR.dtd[ parent.getName() ][ '#' ] )
     303                                {
     304                                        block = block.getParent();
     305                                }
     306
     307                                if ( parent )
     308                                {
     309                                        range.moveToPosition( block, CKEDITOR.POSITION_AFTER_END );
     310
     311                                        // Insert filler node when cursor is at the end of block
     312                                        // or by side of a block.
     313                                        var next;
     314                                        if ( range.checkEndOfBlock() )
     315                                                parent.appendBogus();
     316                                        else if ( ( next = block.getNext() ) && next.type == CKEDITOR.NODE_ELEMENT && next.isBlockBoundary()  )
     317                                        {
     318                                                var filler = CKEDITOR.env.ie ?doc.createText( '\u00a0' ) :
     319                                                                CKEDITOR.env.opera ? doc.createText( '' ) :
     320                                                                doc.createElement( 'br' );
     321
     322                                                filler.insertAfter( block );
     323                                        }
     324                                       
     325                                        range.select();
     326                                }
     327                        }
     328                }
    285329        };
    286330
    287331        var plugin = CKEDITOR.plugins.enterkey,
     
    321365                return true;
    322366        }
    323367
     368        function ctrlShiftEnter( editor )
     369        {
     370                // Use setTimout so the keys get cancelled immediatelly.
     371                setTimeout( function()
     372                        {
     373                                editor.fire( 'saveSnapshot' );  // Save undo step.
     374                                CKEDITOR.plugins.enterkey.enterExit( editor );
     375                                editor.fire( 'saveSnapshot' );  // Save undo step.
     376                        }, 0 );
     377        }
    324378
    325379        function getRange( editor )
    326380        {
  • _source/core/dom/element.js

     
    236236
    237237                appendBogus : function()
    238238                {
    239                         var lastChild = this.getLast() ;
     239                        var nonBookmark = CKEDITOR.dom.walker.bookmark( false, true ),
     240                                nonEmptyspaces = CKEDITOR.dom.walker.whitespaces( true ),
     241                                evaluator = function( node )
     242                                {
     243                                        return nonEmptyspaces( node ) && nonBookmark( node )
     244                                };
    240245
    241                         // Ignore empty/spaces text.
    242                         while ( lastChild && lastChild.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.rtrim( lastChild.getText() ) )
    243                                 lastChild = lastChild.getPrevious();
    244                         if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) )
    245                         {
    246                                 var bogus = CKEDITOR.env.opera ?
    247                                                 this.getDocument().createText('') :
    248                                                 this.getDocument().createElement( 'br' );
     246                        this.appendBogus = function()
     247                        {
     248                                var lastChild = this.getLast( evaluator );
     249                                if ( !lastChild || !lastChild.is || !lastChild.is( 'br' ) )
     250                                {
     251                                        var bogus =     CKEDITOR.env.ie ? this.getDocument().createText( '\u00a0' ) :
     252                                                        CKEDITOR.env.opera ? this.getDocument().createText('') :
     253                                                        this.getDocument().createElement( 'br' );
    249254
    250                                 CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' );
     255                                        CKEDITOR.env.gecko && bogus.setAttribute( 'type', '_moz' );
    251256
    252                                 this.append( bogus );
    253                         }
     257                                        this.append( bogus );
     258                                }
     259                        };
     260
     261                        this.appendBogus();
    254262                },
    255263
    256264                /**
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy