ISSUE DESCRIPTION Bug: List: delete the leading ListItemNode will also delete the…
- User
ISSUE DESCRIPTION
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.)ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
Assistant
Let me start by understanding the repository structure and the issue. The issue is about a bug in Lexical where deleting the first
ListItemNodein aListNodealso deletes the previousDecoratorBlockNode.Let me explore the repository structure first.
Assistant
This is a monorepo with many packages. The issue is about Lists and DecoratorBlockNode. Let me look at the packages directory to understand the structure.
Assistant
The issue involves list and decorator node interactions. Let me explore the relevant
Assistant
Let me do one command at a time.
Assistant
Let me look at the relevant files. The issue likely relates to how delete/backspace is handled. Let me first understand the code structure.
Let me look at the LexicalListNode.ts and LexicalListItemNode.ts.
Assistant
Let me look at the LexicalListNode.ts to understand how list nodes work
Assistant
Let me look at the formatList.ts and utils.ts files since they likely contain deletion logic.
Assistant
Let me see the rest of the file and also the utils.ts.
Assistant
Let me look at the registration and extension files for lists
Assistant
Let me look at the registerList.ts file to understand backspace/delete handling
Assistant
Let me see the full formatList.ts file, specifically the
$removeListfunctionAssistant
Let me continue reading the formatList.ts file.
Assistant
Let me search for how delete/backspace operations are handled in the codebase
Assistant
Let me search for how these delete commands are handled in the codebase
Assistant
Let me look at the rich-text package's handling of delete commands
Assistant
Let me search specifically for the DELETE_CHARACTER_COMMAND handler in the rich-text package
Assistant
Let me look at the delete command handlers around line 750
Assistant
Let me understand the event flow. Let me look at LexicalEvents.ts
Assistant
Let me look at the backspace and delete event handling in LexicalEvents
Assistant
Let me search for where KEY_BACKSPACE_COMMAND is handled
Assistant
Let me see how KEY_BACKSPACE_COMMAND is handled in the rich-text package
Assistant
Now I need to look at the RangeSelection's
deleteCharactermethod. Let me find itAssistant
Let me look at the deleteCharacter method and related functions
Assistant
Let me continue reading
Assistant
Let me continue reading
Assistant
Let me look at the
$collapseAtStartfunctionAssistant
Let me look at that function.
Assistant
Let me check if ListNode or ListItemNode have a
collapseAtStartmethodAssistant
Let me look at the
collapseAtStartmethod in ListItemNodeAssistant
Let me see the full collapseAtStart
Assistant
Let me see the rest
Assistant
Let me look at the list test files
Assistant
Let me check what test files exist.
Assistant
Let me search for tests related to delete and decorator in these test files
Assistant
No results, let me try case-insensitively.
Assistant
Let me search for tests related to this issue more broadly
Assistant
Let me look at these regression tests, especially the list-related one
Assistant
Let me look at the other relevant
Assistant
Let me look at the 7319 test
Assistant
Let me look at
forwardDeletionin `LexicalSelectionAssistant
Let me look at forwardDeletion
Assistant
Let me look at the
$shouldPreventRemoveNodefunctionAssistant
Let me look at recent git history for related changes
Assistant
Let me look at the
$caretFromPointfunctionAssistant
Let me search for `$caretFrom
Assistant
Let me look at the
$caretFromPointfunctionAssistant
Let me look at
$getChildCaretAtIndexAssistant
Let me look at the
Assistant
Let me check the git log for changes to the selection file
Assistant
Let me look at the diff for the "Backspace at block start preserves the current block"
Assistant
Let me see the actual
Assistant
Let me look at the other relevant commit
Assistant
Let me see the diff for this commit
Assistant
Let me look at the list e2e tests related to delete/backspace
Assistant
Let me look at `$getChildCaret
Assistant
Let me look at the
$getChildCaretfunctionAssistant
Let me search for
$getChildCaretdefinitionAssistant
Let me look at the
$getChildCaretfunctionAssistant
Let me search for DecoratorBlockNode
Assistant
Let me look at the DecoratorNode
Assistant
Let me look at `$getCaretInDirection
Assistant
Let me search more broadly
Assistant
Let me look at the `$getCaretInDirection
Assistant
Let me look at the full deleteCharacter logic around the decorator handling
Assistant
Let me find the
iterNodeCaretsmethodAssistant
Let me look at the iterNodeCarets implementation
Assistant
Let me search for DecoratorBlockNode in e2e
Assistant
Let me look at DecoratorBlockNode
Assistant
Let me look at DecoratorBlock
Assistant
Let me look at a relevant test to understand how to create
Assistant
Let me try to run the existing tests for the lexical core first
Assistant
Now I have a clear understanding of the issue. Let me look at the exact code I need to fix.
Assistant
Now let me look at the full context around the decorator handling code to make a proper edit
Assistant
Now I understand the issue clearly. The problem is in
packages/lexical/src/LexicalSelection.tsin thedeleteCharactermethod. When we encounter a decorator node andstate.type === 'initial'(meaning the decorator is the first node encountered, not part of a merge-block chain), the code incorrectly removes the decorator.The fix should break out of the loop when
state.type === 'initial'and a decorator is encountered, letting the subsequentcollapseAtStartlogic handle the case properly.Let me create a script to reproduce the issue first, then apply the fix.
Assistant
Let me apply the fix to LexicalSelection.ts. The change is in the
elsebranch of the decorator handling: whenstate.type === 'initial', we should break instead of removing the decoratorAssistant
Let me use the
opencommand with lineAssistant
Now let me apply the fix. I'll change the
elsebranch to only remove the decorator whenstate.type === 'merge-next-block', and break out when `state.type === 'initial'Assistant
Let me use bash to edit the file.
Assistant
Let me use the replace command
Assistant
Let me verify the fix is structurally correct by looking at the surrounding code
Assistant
Let me check ElementNode's collapseAtStart
Assistant
Let me check ParagraphNode's collapseAtStart
Assistant
Let me look at ParagraphNode's collapseAtStart
Assistant
Let me see the rest of ParagraphNode's collapseAtStart
Assistant
Now let me verify my fix by running the existing tests. Let me first check if the relevant tests compile and pass.
Assistant
Let me run the list package
Assistant
Let me search for deleteCharacter tests related to lists
Assistant
Let me look at that
Assistant
Let me see the rest of that test
Assistant
Let me check how HR nodes work in the playground
Assistant
Let me look at HorizontalRuleNode
Assistant
Let me look at the HorizontalRule
Assistant
Let me look at the git history for the 7319 test
Assistant
Let me look at that commit to understand the related changes
Assistant
Let me see the diff for LexicalSelection.ts from that commit
Assistant
Let me understand the block cursor behavior better
Assistant
Let me look at how block cursor affects selection
Assistant
Let me search for existing unit tests that test the deleteCharacter with decorators
Assistant
Let me verify the final code looks correct
Assistant
Let me look at how block cursor interacts with selection
Assistant
Let me check my diff one more time to make sure everything is correct
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.