Skip to content

Commit

Permalink
fix(list-item): improve delete behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Mar 30, 2023
1 parent b9ba227 commit 09782a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/extension-list-item/src/helpers/index.ts
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions packages/extension-list-item/src/list-item.ts
Expand Up @@ -77,14 +77,19 @@ export const ListItem = Node.create<ListItemOptions>({

// 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
Expand Down

0 comments on commit 09782a5

Please sign in to comment.