Explorar el Código

Fixed pasting nested list.

Kuba Niegowski hace 5 años
padre
commit
831b85db04

+ 1 - 9
packages/ckeditor5-list/src/todolistconverters.js

@@ -9,7 +9,7 @@
 
 /* global document */
 
-import { generateLiInUl, injectViewList, positionAfterUiElements } from './utils';
+import { generateLiInUl, injectViewList, positionAfterUiElements, findNestedList } from './utils';
 import createElement from '@ckeditor/ckeditor5-utils/src/dom/createelement';
 
 /**
@@ -332,11 +332,3 @@ function findDescription( viewItem, view ) {
 		}
 	}
 }
-
-function findNestedList( viewItem ) {
-	for ( const node of viewItem.getChildren() ) {
-		if ( node.name == 'ul' || node.name == 'ol' ) {
-			return node;
-		}
-	}
-}

+ 25 - 1
packages/ckeditor5-list/src/utils.js

@@ -92,7 +92,15 @@ export function injectViewList( modelItem, injectedItem, conversionApi, model )
 			// There could be some not mapped elements (eg. span in to-do list) but we need to insert
 			// a nested list directly inside the li element.
 			const mappedViewAncestor = mapper.findMappedViewAncestor( insertPosition );
-			insertPosition = viewWriter.createPositionAt( mappedViewAncestor, 'end' );
+			const nestedList = findNestedList( mappedViewAncestor );
+
+			// If there already is some nested list, then use it's position.
+			if ( nestedList ) {
+				insertPosition = viewWriter.createPositionBefore( nestedList );
+			} else {
+				// Else just put new list on the end of list item content.
+				insertPosition = viewWriter.createPositionAt( mappedViewAncestor, 'end' );
+			}
 		} else {
 			// The previous item is not a list item (or does not exist at all).
 			// Just map the position and insert the view item at the mapped position.
@@ -255,6 +263,22 @@ export function createUIComponent( editor, commandName, label, icon ) {
 	} );
 }
 
+/**
+ * Returns a first list view element that is direct child of the given view element.
+ *
+ * @param {module:engine/view/element~Element} viewElement
+ * @return {module:engine/view/element~Element|null}
+ */
+export function findNestedList( viewElement ) {
+	for ( const node of viewElement.getChildren() ) {
+		if ( node.name == 'ul' || node.name == 'ol' ) {
+			return node;
+		}
+	}
+
+	return null;
+}
+
 // Implementation of getFillerOffset for view list item element.
 //
 // @returns {Number|null} Block filler offset or `null` if block filler is not needed.