[lexical-playground] Bug Fix: Preserve the selection using the link editor from a table #6865
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
When used in a table cell, the link editor loses focus and the link is not applied. Finding the root cause of this one was tricky, but the gist of it was that we were calling editor.update on mousemove for TableHoverActions and TableCellResizer and because of how reconciliation currently works the DOM selection is always resolved during an editor.update cycle so it would get reset under these circumstances since the DOM selection was in a portal for the link editing modal.
Failed debugging strategies:
$setSelection
What worked:
.link-input
)updateFn
to thescheduleMicroTask(() => { … })
closure so that I could track down which update function was responsible for this happening in the debugger scope (normally this information is lost since that function only closes over editor)Future considerations:
I've never loved how editor reconciliation always tries to eagerly do things with the selection based on the DOM, because of situations like this. Maybe we should at least add an update tag similar to
skip-scroll-into-view
which avoids the forced selection reconciliation without having to temporarily set the editor to readonly or do other weird things.Closes #6821
Test plan
Before
link-edit-before.mov
After
link-edit-after.mov