Skip to content

Commit

Permalink
fix: prevent error in toggleList command, fix #2279
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kühn authored and Philipp Kühn committed Dec 15, 2021
1 parent 47b25a6 commit 66eb2f2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/core/src/commands/toggleList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const joinListBackwards = (tr: Transaction, listType: NodeType): boolean => {
}

const before = tr.doc.resolve(Math.max(0, list.pos - 1)).before(list.depth)

if (before === undefined) {
return true
}

const nodeBefore = tr.doc.nodeAt(before)
const canJoinBackwards = list.node.type === nodeBefore?.type
&& canJoin(tr.doc, list.pos)
Expand All @@ -35,6 +40,11 @@ const joinListForwards = (tr: Transaction, listType: NodeType): boolean => {
}

const after = tr.doc.resolve(list.start).after(list.depth)

if (after === undefined) {
return true
}

const nodeAfter = tr.doc.nodeAt(after)
const canJoinForwards = list.node.type === nodeAfter?.type
&& canJoin(tr.doc, after)
Expand Down

0 comments on commit 66eb2f2

Please sign in to comment.