Skip to content

[lexical][lexical-table] Bug Fix: Delete empty paragraph before table#8669

Open
Rohithmatham12 wants to merge 2 commits into
facebook:mainfrom
Rohithmatham12:fix-delete-before-table
Open

[lexical][lexical-table] Bug Fix: Delete empty paragraph before table#8669
Rohithmatham12 wants to merge 2 commits into
facebook:mainfrom
Rohithmatham12:fix-delete-before-table

Conversation

@Rohithmatham12

@Rohithmatham12 Rohithmatham12 commented Jun 10, 2026

Copy link
Copy Markdown

Description

Forward delete from an empty paragraph immediately before a table was swallowed by the shadow-root protection in RangeSelection.forwardDeletion. That guard correctly prevents deleting the table itself, but it also returned before the empty paragraph could be removed.

This change preserves the protected table behavior while removing the empty anchor paragraph and moving the selection to the table boundary.

Closes #8075

Test plan

Before

Forward delete from an empty paragraph directly before a table left the empty paragraph in place, so the Delete key appeared to do nothing.

After

Forward delete removes the empty paragraph and keeps the table protected. Added regression coverage for the paragraph-before-table case.

Automated tests:

  • node node_modules/vitest/vitest.mjs --project unit packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx --run
  • node node_modules/vitest/vitest.mjs --project unit packages/lexical/src/__tests__/unit/LexicalSelection.test.ts --run
  • node node_modules/prettier/bin/prettier.cjs --check packages/lexical/src/LexicalSelection.ts packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx
  • node node_modules/eslint/bin/eslint.js packages/lexical/src/LexicalSelection.ts packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx

@meta-cla

meta-cla Bot commented Jun 10, 2026

Copy link
Copy Markdown

Hi @Rohithmatham12!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 11, 2026 1:54pm
lexical-playground Ready Ready Preview, Comment Jun 11, 2026 1:54pm

Request Review

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

Assessment: LGTM

This is a clean, well-scoped fix for #8075 (forward delete swallowed by shadow-root guard when an empty paragraph precedes a table).

What I checked:

  • Logic correctness: The new guard only fires when anchor.type === "element" AND anchorNode.isEmpty() — it won't affect paragraphs with content. The shadow-root protection for the table itself is preserved (the return true still fires after removing the empty node).
  • Caret handling: $normalizeCaret($getChildCaret(nextSibling, 'next')) correctly positions selection at the start of the table boundary. $getCaretRange(caret, caret) creates a collapsed selection, which is the expected state after forward-deleting an empty paragraph into a table.
  • Edge cases: The anchorNode.remove() is safe because we've confirmed it's empty. No risk of data loss.
  • Test coverage: The regression test properly reproduces the exact scenario (empty paragraph → table, forward delete from paragraph) and asserts the paragraph is gone while the table remains.
  • www backwards compatibility: No API changes, no signature changes, no export changes. This is a pure behavioral fix for a previously-broken interaction. Safe for www consumers (MLCComposer, XDSRichText, EPS).

Minor note: CLA is unsigned (likely first-time contributor) — that'll need to be resolved before merge.

Ready to approve once CLA is signed and full CI matrix runs.

@meta-cla

meta-cla Bot commented Jun 10, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla 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 Jun 10, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jun 10, 2026
@etrepum

etrepum commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Title and description doesn't match the pull request template

@Rohithmatham12 Rohithmatham12 changed the title Fix forward delete before tables [lexical][lexical-table] Bug Fix: Delete empty paragraph before table Jun 11, 2026
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 key does not delete empty line before a table

3 participants