lexical icon indicating copy to clipboard operation
lexical copied to clipboard

[WIP][lexical][lexical-selection] Manually handle selection around TextNode boundaries

Open etrepum opened this issue 8 months ago • 2 comments

Description

See #7301 - when alternative display is used for TextNode elements (e.g. not inline span) the behavior of the DOM's Selection.modify doesn't really work anymore because it jumps from one container to the next instead of across to the next logical character. By catching these scenarios and moving the DOM selection into the next element in advance this handles all of the (known) scenarios with arrows and deletions.

The arrow keys need to be handled unconditionally at TextNode boundaries because the selection is often out of sync with exactly what the Lexical points are.

Other issues likely still exist when moving by word or line, but character is the important granularity for most situations.

For future consideration we might want to move RangeSelection.modify into a command, or parts of it into a command, so that people can more easily work around these sorts of issues.

Closes #7301

Test plan

TBD - The plan will probably be to add an e2e suite outside of the playground with the project sitting in scripts/__tests__/integration/fixtures/lexical-adjacent-span-deletion which can be used to demonstrate that this bug is fixed.

Before

Run with release version of lexical, observe that arrow keys and delete doesn't work consistently (the provided workarounds useNavigateBase and useSpanDeletion are disabled)

cd scripts/__tests__/integration/fixtures/lexical-adjacent-span-deletion
npm install
npm run dev

After

Run with the monorepo version of lexical, observe that the arrow keys and delete work correctly

cd scripts/__tests__/integration/fixtures/lexical-adjacent-span-deletion
npm install
npm run monorepo:dev

etrepum avatar Mar 12 '25 06:03 etrepum

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 3:27pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 3:27pm

vercel[bot] avatar Mar 12 '25 06:03 vercel[bot]

Ignore the failing unit tests for now, I don't think that suite has any real value as-is (it's testing a mock implementation that doesn't really behave like any real browser) and needs to be converted to an e2e suite.

etrepum avatar Mar 12 '25 06:03 etrepum