+ // Check if node is block element that recieves text.\r
+ function isTextBlock( node )\r
+ {\r
+ return node.type == CKEDITOR.NODE_ELEMENT &&\r
+ ( node.getName() in CKEDITOR.dtd.$block ||\r
+ node.getName() in CKEDITOR.dtd.$listItem ) &&\r
+ CKEDITOR.dtd[ node.getName() ][ '#' ];\r
+ }\r
+\r
+ // Merge the visual line content at the cursor range into the block.\r
+ function joinNextLineToCursor( editor, cursor, nextCursor )\r
+ {\r
+ editor.fire( 'saveSnapshot' );\r
+\r
+ // Merge with previous block's content.\r
+ nextCursor.enlarge( CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS );\r
+ var frag = nextCursor.extractContents();\r
+\r
+ cursor.trim( false, true );\r
+\r
+ // Kill original bogus;\r
+ var currentPath = new CKEDITOR.dom.elementPath( cursor.startContainer );\r
+ var currentLi = currentPath.lastElement.getAscendant( 'li', 1 );\r
+\r
+ var bogus = currentPath.block.getBogus();\r
+ bogus && bogus.remove();\r
+\r
+ // Kill the tail br in extracted.\r
+ var last = frag.getLast();\r
+ if ( last && last.type == CKEDITOR.NODE_ELEMENT && last.is( 'br' ) )\r
+ last.remove();\r
+\r
+ // Insert fragment at the range position.\r
+ var nextNode = cursor.startContainer.getChild( cursor.startOffset );\r
+ if ( nextNode )\r
+ frag.insertBefore( nextNode );\r
+ else\r
+ cursor.startContainer.append( frag );\r
+\r
+ var nextPath = new CKEDITOR.dom.elementPath( nextCursor.startContainer );\r
+ var nextLi = nextCursor.startContainer.getAscendant( 'li', 1 );\r
+\r
+ // Move the sub list nested in the next list item.\r
+ if ( nextLi )\r
+ {\r
+ var sublist = getSubList( nextLi );\r
+ if ( sublist )\r
+ {\r
+ // If next line is in the sub list of the current list item.\r
+ if ( currentLi.contains( nextLi ) )\r
+ {\r
+ mergeListItems( sublist, nextLi.getParent(), nextLi );\r
+ sublist.remove();\r
+ }\r
+ // Migrate the sub list to current list item.\r
+ else\r
+ currentLi.append( sublist );\r
+ }\r
+ }\r
+\r
+\r
+ if ( nextCursor.checkStartOfBlock() &&\r
+ nextCursor.checkEndOfBlock() )\r
+ {\r
+ var nextBlock = nextPath.block,\r
+ parentBlock = nextBlock.getParent();\r
+\r
+ nextBlock.remove();\r
+\r
+ // Remove if the path block container is now empty, e.g. li.\r
+ if ( parentBlock &&\r
+ !parentBlock.getFirst( nonEmpty ) &&\r
+ !parentBlock.equals( nextPath.blockLimit ) )\r
+ {\r
+ parentBlock.remove();\r
+ }\r
+ }\r
+\r
+ // Make fresh selection.\r
+ cursor.select();\r
+\r
+ editor.fire( 'saveSnapshot' );\r
+ }\r
+\r
+ function getSubList( li )\r
+ {\r
+ var last = li.getLast( nonEmpty );\r
+ return last && last.type == CKEDITOR.NODE_ELEMENT && last.getName() in listNodeNames ? last : null;\r
+ }\r
+\r