Ticket #6841: 6841.patch

File 6841.patch, 3.4 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/enterkey/plugin.js

     
    3131
    3232                        var doc = range.document;
    3333
    34                         // Exit the list when we're inside an empty list item block. (#5376)
    35                         if ( range.checkStartOfBlock() && range.checkEndOfBlock() )
    36                         {
    37                                 var path = new CKEDITOR.dom.elementPath( range.startContainer ),
    38                                                 block = path.block;
     34                        var atBlockStart = range.checkStartOfBlock(),
     35                                atBlockEnd = range.checkEndOfBlock(),
     36                                path = new CKEDITOR.dom.elementPath( range.startContainer ),
     37                                block = path.block;
    3938
     39                        // Exit the list when we're inside an empty list item block. (#5376)
     40                        if ( atBlockStart && atBlockEnd )
     41                        {
    4042                                if ( block && ( block.is( 'li' ) || block.getParent().is( 'li' ) ) )
    4143                                {
    4244                                        editor.execCommand( 'outdent' );
    4345                                        return;
    4446                                }
    4547                        }
     48                        // Don't split <pre> if we're in the middle of it, act as shift enter key.
     49                        else if ( !atBlockEnd && block.is( 'pre' ) )
     50                                return enterBr( editor, mode, range, forceMode );
    4651
    4752                        // Determine the block element to be used.
    4853                        var blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' );
     
    106111                                        // Do not enter this block if it's a header tag, or we are in
    107112                                        // a Shift+Enter (#77). Create a new block element instead
    108113                                        // (later in the code).
    109                                         if ( previousBlock.is( 'li' ) || !headerTagRegex.test( previousBlock.getName() ) )
     114                                        if ( previousBlock.is( 'li' ) ||
     115                                                        ! ( headerTagRegex.test( previousBlock.getName() ) || previousBlock.is( 'pre' ) ) )
    110116                                        {
    111117                                                // Otherwise, duplicate the previous block.
    112118                                                newBlock = previousBlock.clone();
     
    328334                // On SHIFT+ENTER:
    329335                // 1. We want to enforce the mode to be respected, instead
    330336                // of cloning the current block. (#77)
    331                 // 2. Always perform a block break when inside <pre> (#5402).
    332                 if ( editor.getSelection().getStartElement().hasAscendant( 'pre', true ) )
    333                 {
    334                         setTimeout( function() { enterBlock( editor, editor.config.enterMode, null, true ); }, 0 );
    335                         return true;
    336                 }
    337                 else
    338                         return enter( editor, editor.config.shiftEnterMode, 1 );
     337                return enter( editor, editor.config.shiftEnterMode, 1 );
    339338        }
    340339
    341340        function enter( editor, mode, forceMode )
     
    353352                setTimeout( function()
    354353                        {
    355354                                editor.fire( 'saveSnapshot' );  // Save undo step.
    356                                 if ( mode == CKEDITOR.ENTER_BR || editor.getSelection().getStartElement().hasAscendant( 'pre', 1 ) )
     355                                if ( mode == CKEDITOR.ENTER_BR )
    357356                                        enterBr( editor, mode, null, forceMode );
    358357                                else
    359358                                        enterBlock( editor, mode, null, forceMode );
  • _source/core/dom/range.js

     
    278278                        if ( node.type == CKEDITOR.NODE_TEXT )
    279279                        {
    280280                                // If there's any visible text, then we're not at the start.
    281                                 if ( CKEDITOR.tools.trim( node.getText() ).length )
     281                                if ( node.hasAscendant( 'pre' ) || CKEDITOR.tools.trim( node.getText() ).length )
    282282                                        return false;
    283                                 }
     283                        }
    284284                        else if ( node.type == CKEDITOR.NODE_ELEMENT )
    285285                        {
    286286                                // If there are non-empty inline elements (e.g. <img />), then we're not
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy