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 check existing tests covering deletion around decorators to understand sanctioned behavior:
- Assistant
All cases behave correctly. Now run the broader test suites for regressions:
- Assistant
Full unit suite passes (3822 tests, 163 files). Now typecheck and lint the change:
- Assistant
The fix is complete and verified.
Summary
Bug: Pressing backspace at the start of the leading
ListItemNodeof a list that follows a block-levelDecoratorBlockNode(e.g. aTweetNode) deleted the decorator node.Root cause (
packages/lexical/src/LexicalSelection.ts,RangeSelection.deleteCharacter): when the caret walks backward looking for something to merge/delete, it exits theListItemNodeand then theListNode, updating themerge-next-blockstate each time. When it then encounters a decorator, the code assumed the decorator was adjacent to the anchor's own block and removed it — but here the decorator is only adjacent to an (the ) of the anchor's block.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.