From 66eb2f2a47cdf21590881153a6cb6b1f3f38641a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Wed, 15 Dec 2021 10:51:23 +0100 Subject: [PATCH] fix: prevent error in toggleList command, fix #2279 --- packages/core/src/commands/toggleList.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index 50c29ded1e1..d59c3f6941b 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -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) @@ -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)