[WIP][lexical][lexical-selection] Manually handle selection around TextNode boundaries #7317
+7,270
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
anduseSpanDeletion
are disabled)After
Run with the monorepo version of lexical, observe that the arrow keys and delete work correctly