From 3a7063b83806582cf1626f821e6c526a596c3a7f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 17 Mar 2026 05:00:00 +0000 Subject: [PATCH] fix: list item sigil node --- src/lib/editor/plugins/ListItemPlugin.ts | 14 ++++++++++++++ tests/integration/editor.spec.ts | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/lib/editor/plugins/ListItemPlugin.ts b/src/lib/editor/plugins/ListItemPlugin.ts index 95bfd448..0fd9fd68 100644 --- a/src/lib/editor/plugins/ListItemPlugin.ts +++ b/src/lib/editor/plugins/ListItemPlugin.ts @@ -206,6 +206,20 @@ const destroyListItemSigil = (lisNode: ListItemSigilNode) => { return; } + // Sigil inside ListItemNode absorbed extra text (e.g. user typed + // inside the "- " sigil): mark the parent dirty so + // listItemNodeNormalizationTransform re-splits the sigil. + const liParent = lisNode.getParent(); + if ( + $isListItemNode(liParent) + && liParent.getFirstChild() === lisNode + && lisNode.getTextContentSize() > 2 + && lisNode.getTextContent().startsWith("- ") + ) { + liParent.markDirty(); + return; + } + const previousSibling = lisNode.getPreviousSibling(); const nextSibling = lisNode.getNextSibling(); diff --git a/tests/integration/editor.spec.ts b/tests/integration/editor.spec.ts index 09786333..b68bc953 100644 --- a/tests/integration/editor.spec.ts +++ b/tests/integration/editor.spec.ts @@ -1405,4 +1405,28 @@ bar`); .toBe("abc"); }, ); + + test( + "typing in middle of list item sigil should not add text to sigil node", + async ({ page }) => { + await page.keyboard.type("- 1", { delay: 100 }); + // Move cursor 2 to the left (into the sigil "- ") + await page.keyboard.press("ArrowLeft", { delay: 100 }); + await page.keyboard.press("ArrowLeft", { delay: 100 }); + // Type " 1" — the "1" should end up in the content node, not sigil + await page.keyboard.type(" 1", { delay: 100 }); + + const paragraph = page.locator( + "div[data-lexical-editor] .editor-paragraph:nth-child(1)", + ); + + await expect(paragraph).toHaveClass(/list-item/); + + const sigil = paragraph.locator(".list-item-sigil"); + const content = paragraph.locator(".list-item-content"); + + await expect(sigil).toHaveText("- "); + await expect(content).toHaveText("1 1"); + }, + ); });