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

[WIP][lexical-rich-text][lexical-playground] Bug Fix: Prevent unnecessary history entries on DELETE_CHARACTER_COMMAND #7222

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kirandash
Copy link
Contributor

Description

Currently, when pressing backspace at the start of a heading with content:

  1. The collapseAtStart method in HeadingNode creates unnecessary history entries even when no actual changes occur
  2. This leads to multiple undo operations being required to revert actual changes

Changes in this PR:

  1. Simplify HeadingNode.collapseAtStart() to:
    • Return early with true when node has content (preventing unnecessary node creation)
    • Only create and replace with paragraph node when heading is empty
  2. Improve test coverage for HeadingNode backspace behavior
  3. Fix test assertions to properly verify history entries
  4. Add multiple backspace operation tests to ensure no history pollution

Closes #5350

Test plan

Before

lexical-5350-bug.mov

After

lexical-5350-fix.mov

- Simplify HeadingNode's collapseAtStart to prevent unnecessary node recreation
- Return early when no actual changes are needed
- Fixes facebook#5350 - DELETE_CHARACTER_COMMAND pushing meaningless history entries
- Fix test assertion for backspace at start of heading with no content
- Fix test assertion for backspace at start of heading with content
- Add multiple backspace operations to verify no history pollution
- Properly verify undo behavior reverts to previous meaningful state

Part of fix for facebook#5350 - DELETE_CHARACTER_COMMAND pushing meaningless history
Copy link

vercel bot commented Feb 20, 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 Feb 24, 2025 6:05pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 24, 2025 6:05pm

@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 Feb 20, 2025
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Feb 20, 2025
@kirandash kirandash marked this pull request as draft February 20, 2025 18:21
@kirandash kirandash changed the title [lexical-rich-text][lexical-playground] Bug Fix: Prevent unnecessary history entries on DELETE_CHARACTER_COMMAND [WIP][lexical-rich-text][lexical-playground] Bug Fix: Prevent unnecessary history entries on DELETE_CHARACTER_COMMAND Feb 20, 2025
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: DELETE_CHARACTER_COMMAND pushes meaningless history
3 participants