diff --git a/packages/extension-list-item/src/helpers/index.ts b/packages/extension-list-item/src/helpers/index.ts index cb3ff45c97..7de6f6d78d 100644 --- a/packages/extension-list-item/src/helpers/index.ts +++ b/packages/extension-list-item/src/helpers/index.ts @@ -6,12 +6,13 @@ export const findListItemPos = (typeOrName: string | NodeType, state: EditorStat const { $from } = state.selection const nodeType = getNodeType(typeOrName, state.schema) + let currentNode = null let currentDepth = $from.depth let currentPos = $from.pos let targetDepth: number | null = null while (currentDepth > 0 && targetDepth === null) { - const currentNode = $from.node(currentDepth) + currentNode = $from.node(currentDepth) if (currentNode.type === nodeType) { targetDepth = currentDepth diff --git a/packages/extension-list-item/src/list-item.ts b/packages/extension-list-item/src/list-item.ts index d7e4853c73..b104e02ac1 100644 --- a/packages/extension-list-item/src/list-item.ts +++ b/packages/extension-list-item/src/list-item.ts @@ -77,14 +77,19 @@ export const ListItem = Node.create({ // check if the next node is a list with a deeper depth if (nextListIsDeeper(this.name, editor.state)) { - return editor.chain().focus(editor.state.selection.from + 4) + return editor + .chain() + .focus(editor.state.selection.from + 4) .lift(this.name) .joinBackward() .run() } if (nextListIsHigher(this.name, editor.state)) { - return editor.chain().joinForward().joinListItemForward(this.name).run() + return editor.chain() + .joinForward() + .joinBackward() + .run() } // check if the next node is also a listItem