Skip to content

Fix #3341: Preserve selection marker when reconciling range across two text nodes#3342

Open
JiuqingSong wants to merge 1 commit into
masterfrom
fix-3341-preserve-marker-cross-text-node
Open

Fix #3341: Preserve selection marker when reconciling range across two text nodes#3342
JiuqingSong wants to merge 1 commit into
masterfrom
fix-3341-preserve-marker-cross-text-node

Conversation

@JiuqingSong
Copy link
Copy Markdown
Collaborator

Summary

  • DomIndexerImpl.reconcileSelection was losing the SelectionMarker inserted by the first reconcileNodeSelection call when handling a range that spans two text nodes. The second call's adjacent-marker cleanup loop absorbed marker1 if it ended up directly next to the second text node's segment (notably when startOffset == startContainer.nodeValue.length). setSelection then orphaned both markers and the selected segment never received isSelected.
  • Fix: thread the first call's marker into the second call as preserveMarker; the cleanup loops now skip that specific reference while still absorbing other adjacent stale markers.
  • Added a regression test (Repro #3341: range across two text nodes with startOffset at end of first node) that verifies the full paragraph model after the action.

Test plan

  • yarn eslint — clean
  • yarn test:fast — 5840 passing (includes the new regression test)
  • yarn b — build succeeds

Fixes #3341

🤖 Generated with Claude Code

…o text nodes

When DomIndexerImpl.reconcileSelection handles a non-collapsed range whose
start and end are in different text nodes, it calls reconcileNodeSelection
twice. The second call's adjacent-marker cleanup loop could absorb the
SelectionMarker freshly inserted by the first call (e.g. when startOffset
equals the start text node's length, so marker1 lands directly next to the
end text node's segment). The dangling marker reference then caused
setSelection to orphan both markers, leaving the selected segment without
isSelected.

Pass the first call's marker into the second call as preserveMarker; the
cleanup loops now skip that specific reference while still absorbing any
other adjacent stale markers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@haven2world haven2world left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed to set selection in Content Model when the selection crosses 2 text nodes

2 participants