[lexical][lexical-table] Bug Fix: Delete empty paragraph before table
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 --runnode node_modules/vitest/vitest.mjs --project unit packages/lexical/src/__tests__/unit/LexicalSelection.test.ts --runnode 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.tsxnode 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
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!
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| lexical | Preview, Comment | Jun 21, 2026 8:18pm | |
| lexical-playground | Preview, Comment | Jun 21, 2026 8:18pm |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
Title and description doesn't match the pull request template
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.
Addressed the review feedback in 11bc41970:
- switched
forwardDeletionto 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
RangeSelectionreturned byparagraph.select() - added an assertion for the post-delete selection anchor
- added a core selection test with
TestShadowRootNodeto 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
Superseded by #9058
Thanks for the update. Sounds good, I’ll leave this closed since #9058 supersedes it.