X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Flist%2Fplugin.js;h=dfc24b10c2a6bbf7d321fd504cded5d9d1f3ff54;hp=373f9142bc2e4d722832c53d9a8c7e36bc072ba4;hb=fb481ba0a7d298e3e7b9034fcb9f2afdc6e8e796;hpb=6e682412d5cc0dfaedb376482e585bf2989c6863 diff --git a/_source/plugins/list/plugin.js b/_source/plugins/list/plugin.js index 373f914..dfc24b1 100644 --- a/_source/plugins/list/plugin.js +++ b/_source/plugins/list/plugin.js @@ -784,7 +784,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license CKEDITOR.dtd[ node.getName() ][ '#' ]; } - // Merge the visual line content at the cursor range into the block. + // Join visually two block lines. function joinNextLineToCursor( editor, cursor, nextCursor ) { editor.fire( 'saveSnapshot' ); @@ -797,14 +797,29 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var bm = cursor.createBookmark(); // Kill original bogus; - var currentPath = new CKEDITOR.dom.elementPath( cursor.startContainer ); - var currentLi = currentPath.lastElement.getAscendant( 'li', 1 ); - - var bogus = currentPath.block.getBogus(); - bogus && bogus.remove(); + var currentPath = new CKEDITOR.dom.elementPath( cursor.startContainer ), + pathBlock = currentPath.block, + currentBlock = currentPath.lastElement.getAscendant( 'li', 1 ) || pathBlock, + nextPath = new CKEDITOR.dom.elementPath( nextCursor.startContainer ), + nextLi = nextPath.contains( CKEDITOR.dtd.$listItem ), + nextList = nextPath.contains( CKEDITOR.dtd.$list ), + last; + + // Remove bogus node the current block/pseudo block. + if ( pathBlock ) + { + var bogus = pathBlock.getBogus(); + bogus && bogus.remove(); + } + else if ( nextList ) + { + last = nextList.getPrevious( nonEmpty ); + if ( last && blockBogus( last ) ) + last.remove(); + } // Kill the tail br in extracted. - var last = frag.getLast(); + last = frag.getLast(); if ( last && last.type == CKEDITOR.NODE_ELEMENT && last.is( 'br' ) ) last.remove(); @@ -815,9 +830,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else cursor.startContainer.append( frag ); - var nextPath = new CKEDITOR.dom.elementPath( nextCursor.startContainer ); - var nextLi = nextCursor.startContainer.getAscendant( 'li', 1 ); - // Move the sub list nested in the next list item. if ( nextLi ) { @@ -825,14 +837,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( sublist ) { // If next line is in the sub list of the current list item. - if ( currentLi.contains( nextLi ) ) + if ( currentBlock.contains( nextLi ) ) { mergeChildren( sublist, nextLi.getParent(), nextLi ); sublist.remove(); } // Migrate the sub list to current list item. else - currentLi.append( sublist ); + currentBlock.append( sublist ); } } @@ -918,19 +930,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !range.collapsed ) return; + var path = new CKEDITOR.dom.elementPath( range.startContainer ); var isBackspace = key == 8; var body = editor.document.getBody(); var walker = new CKEDITOR.dom.walker( range.clone() ); walker.evaluator = function( node ) { return nonEmpty( node ) && !blockBogus( node ); }; + // Backspace/Del behavior at the start/end of table is handled in core. + walker.guard = function( node, isOut ) { return !( isOut && node.type == CKEDITOR.NODE_ELEMENT && node.is( 'table' ) ); }; + var cursor = range.clone(); if ( isBackspace ) { var previous, joinWith; - var path = new CKEDITOR.dom.elementPath( range.startContainer ); - // Join a sub list's first line, with the previous visual line in parent. if ( ( previous = path.contains( listNodeNames ) ) && range.checkBoundaryOfElement( previous, CKEDITOR.START ) && @@ -973,10 +987,43 @@ For licensing, see LICENSE.html or http://ckeditor.com/license joinNextLineToCursor( editor, cursor, range ); evt.cancel(); } + else + { + var list = path.contains( listNodeNames ), li; + // Backspace pressed at the start of list outdents the first list item. (#9129) + if ( list && range.checkBoundaryOfElement( list, CKEDITOR.START ) ) + { + li = list.getFirst( nonEmpty ); + + if ( range.checkBoundaryOfElement( li, CKEDITOR.START ) ) + { + previous = list.getPrevious( nonEmpty ); + + // Only if the list item contains a sub list, do nothing but + // simply move cursor backward one character. + if ( getSubList( li ) ) + { + if ( previous ) { + range.moveToElementEditEnd( previous ); + range.select(); + } + + evt.cancel(); + } + else + { + editor.execCommand( 'outdent' ); + evt.cancel(); + } + } + } + } } else { - var li = range.startContainer.getAscendant( 'li', 1 ); + var next, nextLine; + li = range.startContainer.getAscendant( 'li', 1 ); + if ( li ) { walker.range.setEndAt( body, CKEDITOR.POSITION_BEFORE_END ); @@ -987,7 +1034,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Indicate cursor at the visual end of an list item. var isAtEnd = 0; - var next = walker.next(); + next = walker.next(); // When list item contains a sub list. if ( next && next.type == CKEDITOR.NODE_ELEMENT && @@ -1007,13 +1054,56 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( isAtEnd && next ) { // Put cursor range there. - var nextLine = range.clone(); + nextLine = range.clone(); nextLine.moveToElementEditStart( next ); joinNextLineToCursor( editor, cursor, nextLine ); evt.cancel(); } } + else + { + // Handle Del key pressed before the list. + walker.range.setEndAt( body, CKEDITOR.POSITION_BEFORE_END ); + next = walker.next(); + + if ( next && next.type == CKEDITOR.NODE_ELEMENT && + next.getName() in listNodeNames ) + { + // The start
  • + next = next.getFirst( nonEmpty ); + + // Simply remove the current empty block, move cursor to the + // subsequent list. + if ( path.block && + range.checkStartOfBlock() && + range.checkEndOfBlock() ) + { + path.block.remove(); + range.moveToElementEditStart( next ); + range.select(); + evt.cancel(); + } + + // Preventing the default (merge behavior), but simply move + // the cursor one character forward if subsequent list item + // contains sub list. + else if ( getSubList( next ) ) + { + range.moveToElementEditStart( next ); + range.select(); + evt.cancel(); + } + // Merge the first list item with the current line. + else + { + nextLine = range.clone(); + nextLine.moveToElementEditStart( next ); + joinNextLineToCursor( editor, cursor, nextLine ); + evt.cancel(); + } + } + } } // The backspace/del could potentially put cursor at a bad position,