Bug: List: delete the leading ListItemNode will also delete the previous…
- User
Bug: List: delete the leading ListItemNode will also delete the previous DecoratorBlockNode Lexical version: 0.12.2
Steps To Reproduce
- Open the playground at https://playground.lexical.dev/
- Append a
DecoratorBlockNodeto the document, for example, aTweetNode - Insert a list after the
DecoratorBlockNode - Delete the first list item, and the previous
DecoratorBlockNodewill also be removed
https://github.com/facebook/lexical/assets/6022672/2ccbc2a0-af27-4d3f-a244-804f43249fec
The current behavior
Both the
ListNodeand the previousDecoratorBlockNodeare deleted.The expected behavior
Only
ListNodewould be deleted. (I will be more than happy to see theListNodebe replaced by aParagraphNodeif possible! That's the default behavior in other editors.)Interface
No new interfaces are introduced.
- Assistant
Now let me write a scratch repro test to confirm the behavior in the current code:
- Assistant
Reproduced: with text in the first list item, the decorator gets deleted. The empty-item case is already handled. Now let me look at
$collapseAtStart: - Assistant
Now let me check
collapseAtStartimplementations in core nodes: - Assistant
Now the decorator branch:
- Assistant
Both pass. Let me strengthen the scratch test with structural assertions and cover more cases (multi-item list, forward delete):
- Assistant
All 5 pass. Now run the broader unit suites to check for regressions:
- Assistant
The bug is fixed. Summary of what I did:
Root cause
In
RangeSelection.deleteCharacter(packages/lexical/src/LexicalSelection.ts), the backward-deletion exploration walks carets from the anchor toward the previous node. When it reaches aDecoratorNodewhile in themerge-next-blockstate, it removed that decorator whenever the anchor wasn't an empty element — without checking whether the decorator was actually adjacent to the . With a cursor at the start of the first , the walk ascends through block boundaries ( → ) before hitting the decorator, which is only adjacent to the ancestor — yet the decorator got deleted.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.