lexical icon indicating copy to clipboard operation
lexical copied to clipboard

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

Open Rohithmatham12 opened this issue 5 months ago • 6 comments

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 and for the shared shadow-root path.

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/src/__tests__/unit/LexicalSelection.test.ts packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx
  • node node_modules/eslint/bin/eslint.js packages/lexical/src/LexicalSelection.ts packages/lexical/src/__tests__/unit/LexicalSelection.test.ts packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx

Rohithmatham12 avatar Jun 10 '26 18:06 Rohithmatham12

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 [email protected]. Thanks!

meta-cla[bot] avatar Jun 10 '26 18:06 meta-cla[bot]

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 21, 2026 8:18pm
lexical-playground Ready Ready Preview, Comment Jun 21, 2026 8:18pm

Request Review

vercel[bot] avatar Jun 10 '26 18:06 vercel[bot]

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[bot] avatar Jun 10 '26 19:06 meta-cla[bot]

Title and description doesn't match the pull request template

etrepum avatar Jun 11 '26 04:06 etrepum

Looks good overall — a few suggestions inline on test coverage, a minor convention thing, and an alternative approach that avoids duplicating the existing backward-delete block in deleteCharacter.

mayrang avatar Jun 21 '26 15:06 mayrang

Addressed the review feedback in 11bc41970:

  • switched forwardDeletion to invert the shadow-root guard so empty-anchor shadow-root deletion falls through to the existing shared caret path
  • updated the table regression test to use the RangeSelection returned by paragraph.select()
  • added an assertion for the post-delete selection anchor
  • added a core selection test with TestShadowRootNode to cover non-table shadow roots

Re-ran:

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/src/__tests__/unit/LexicalSelection.test.ts packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx
node node_modules/eslint/bin/eslint.js packages/lexical/src/LexicalSelection.ts packages/lexical/src/__tests__/unit/LexicalSelection.test.ts packages/lexical-table/src/__tests__/unit/LexicalTableSelection.test.tsx

Rohithmatham12 avatar Jun 21 '26 20:06 Rohithmatham12

Superseded by #9058

etrepum avatar Aug 30 '26 18:08 etrepum

Thanks for the update. Sounds good, I’ll leave this closed since #9058 supersedes it.

Rohithmatham12 avatar Aug 30 '26 20:08 Rohithmatham12