|
|
@@ -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.
|