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
Investigating list deletion logic and its interaction with DecoratorBlockNode — I'll search the codebase for the relevant handlers.
- Assistant
I'll write a test to reproduce the bug, then trace the deletion logic.
- Assistant
Bug reproduced. Checking what remains after deletion:
- Assistant
The issue is that
deleteCharacterremoves the decorator beforecollapseAtStartruns. I'll move thecollapseAtStartcheck earlier in that flow. - Assistant
Test passes. Running broader test suites to check for regressions:
- Assistant
Fixed. Backspace at the start of the first list item was deleting the previous
DecoratorBlockNodebecausedeleteCharacterremoved adjacent decorators beforeListItemNode.collapseAtStart()could run.Root cause
When backspacing at offset 0 with no text behind the cursor,
deleteCharacterinLexicalSelection.tswalks backward looking for blocks to merge. If it finds a non-inline decorator (likeTweetNode) before the list, it removes that decorator and returns early — beforeListItemNode.collapseAtStart()gets a chance to convert the list to a paragraph.Fix
Call
$collapseAtStartearlier indeleteCharacter, right after theforwardDeletioncheck and before the merge/decorator logic:1771:1776:packages/lexical/src/LexicalSelection.tsif (isBackward && anchor.offset === 0) { if ($collapseAtStart(this, anchorNode)) { return; } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.