Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking Change][lexical][lexical-playground] Feature: Add a default delete handler for NodeSelection #7323

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented Mar 12, 2025

Breaking Change

If you have any $onDelete handlers copied from the playground for KEY_DELETE_COMMAND and KEY_BACKSPACE_COMMAND, you can delete them all now. If you leave them in, it will have similar bugs as prior to this PR.

The default KEY_DELETE_COMMAND and KEY_BACKSPACE_COMMAND handlers now preventDefault and call DELETE_CHARACTER_COMMAND for NodeSelection (in addition to the existing RangeSelection behavior).

The DELETE_CHARACTER_COMMAND handler now handles NodeSelection by calling the new NodeSelection.deleteNodes() method which places a new RangeSelection where the first selected node was (if any, and if it was the current selection) and then removes all of the selected nodes.

Description

NodeSelection has no default handler for when the delete or backspace keys are pressed. This results in having every individual decorator node plugin register the same handler to incorrectly deal with this situation.

By centralizing the handler to a default location we can fix up the selection after a delete and remove a bunch of boilerplate code (while still having the option to override this behavior in the same way).

Closes #7319

Test plan

New e2e regression tests added to catch this specific behavior

Copy link

vercel bot commented Mar 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 9:16pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 9:16pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 12, 2025
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 12, 2025
@etrepum etrepum marked this pull request as ready for review March 12, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: when deleting consecutive DecoratorNodes, sometimes two are deleted at once
2 participants