Ticket #12177: 0001-Paragraph-in-list-on-shift-enter.patch

File 0001-Paragraph-in-list-on-shift-enter.patch, 4.0 KB (added by Piotr Jasiun, 10 years ago)
  • plugins/enterkey/plugin.js

    From 412015d8086eb63212c3c15a1bd05c4aa120b246 Mon Sep 17 00:00:00 2001
    From: Piotr Jasiun <p.jasiun@cksource.com>
    Date: Thu, 9 Oct 2014 11:19:50 +0200
    Subject: [PATCH] Paragraph in list on shift-enter.
    
    ---
     plugins/enterkey/plugin.js | 36 ++++++++++++++++++++++++++++--------
     1 file changed, 28 insertions(+), 8 deletions(-)
    
    diff --git a/plugins/enterkey/plugin.js b/plugins/enterkey/plugin.js
    index cd94c92..546c2a3 100644
    a b  
    3333                bookmark = CKEDITOR.dom.walker.bookmark();
    3434
    3535        CKEDITOR.plugins.enterkey = {
    36                 enterBlock: function( editor, mode, range, forceMode ) {
     36                enterBlock: function( editor, mode, range, forceMode, shiftEnter ) {
    3737                        // Get the range for the current selection.
    3838                        range = range || getRange( editor );
    3939
     
    5252                                atBlockEnd = range.checkEndOfBlock(),
    5353                                path = editor.elementPath( range.startContainer ),
    5454                                block = path.block,
     55                                liBookmark, p,
    5556
    5657                                // Determine the block element to be used.
    5758                                blockTag = ( mode == CKEDITOR.ENTER_DIV ? 'div' : 'p' ),
     
    271272                                }
    272273                        }
    273274
     275                        // Put <p> into <li> and move the content:
     276                        // <li>foo[]</li>  -> <li><p>foo[]</p></li>
     277                        if ( shiftEnter && block.is( 'li' ) ) {
     278                                liBookmark = range.createBookmark(),
     279                                p = new CKEDITOR.dom.element( 'p' );
     280
     281                                block.moveChildren( p );
     282                                block.append( p );
     283                                block = p;
     284
     285                                range.moveToBookmark( liBookmark );
     286                        }
     287
    274288                        // Split the range.
    275289                        var splitInfo = range.splitBlock( blockTag );
    276290
     
    289303                        // If this is a block under a list item, split it as well. (#1647)
    290304                        if ( nextBlock ) {
    291305                                node = nextBlock.getParent();
    292                                 if ( node.is( 'li' ) ) {
     306                                if ( !shiftEnter && node.is( 'li' ) ) {
    293307                                        nextBlock.breakParent( node );
    294308                                        nextBlock.move( nextBlock.getNext(), 1 );
    295309                                }
    296                         } else if ( previousBlock && ( node = previousBlock.getParent() ) && node.is( 'li' ) ) {
     310                        } else if ( previousBlock && ( node = previousBlock.getParent() ) && !shiftEnter && node.is( 'li' ) ) {
    297311                                previousBlock.breakParent( node );
    298312                                node = previousBlock.getNext();
    299313                                range.moveToElementEditStart( node );
     
    307321                                // If the next block is an <li> with another list tree as the first
    308322                                // child, we'll need to append a filler (<br>/NBSP) or the list item
    309323                                // wouldn't be editable. (#1420)
    310                                 if ( nextBlock.is( 'li' ) ) {
     324                                if ( !shiftEnter && nextBlock.is( 'li' ) ) {
    311325                                        var walkerRange = range.clone();
    312326                                        walkerRange.selectNodeContents( nextBlock );
    313327                                        var walker = new CKEDITOR.dom.walker( walkerRange );
     
    330344                                        // Do not enter this block if it's a header tag, or we are in
    331345                                        // a Shift+Enter (#77). Create a new block element instead
    332346                                        // (later in the code).
    333                                         if ( previousBlock.is( 'li' ) || !( headerTagRegex.test( previousBlock.getName() ) || previousBlock.is( 'pre' ) ) ) {
     347                                        if ( ( !shiftEnter && previousBlock.is( 'li' ) ) || !( headerTagRegex.test( previousBlock.getName() ) || previousBlock.is( 'pre' ) ) ) {
    334348                                                // Otherwise, duplicate the previous block.
    335349                                                newBlock = previousBlock.clone();
    336350                                        }
     
    494508                headerTagRegex = /^h[1-6]$/;
    495509
    496510        function shiftEnter( editor ) {
     511                var mode = editor.activeShiftEnterMode,
     512                        path = editor.elementPath();
     513
     514                if ( path.contains( 'li' ) ) {
     515                        mode = CKEDITOR.ENTER_P;
     516                }
    497517                // On SHIFT+ENTER:
    498518                // 1. We want to enforce the mode to be respected, instead
    499519                // of cloning the current block. (#77)
    500                 return enter( editor, editor.activeShiftEnterMode, 1 );
     520                return enter( editor, mode, 1, 1 );
    501521        }
    502522
    503         function enter( editor, mode, forceMode ) {
     523        function enter( editor, mode, forceMode, shiftEnter ) {
    504524                forceMode = editor.config.forceEnterMode || forceMode;
    505525
    506526                // Only effective within document.
     
    524544                if ( mode == CKEDITOR.ENTER_BR )
    525545                        enterBr( editor, mode, null, forceMode );
    526546                else
    527                         enterBlock( editor, mode, null, forceMode );
     547                        enterBlock( editor, mode, null, forceMode, shiftEnter );
    528548
    529549                editor.fire( 'saveSnapshot' );
    530550        }
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy