Fix #3341: Preserve selection marker when reconciling range across two text nodes#3342
Open
JiuqingSong wants to merge 1 commit into
Open
Fix #3341: Preserve selection marker when reconciling range across two text nodes#3342JiuqingSong wants to merge 1 commit into
JiuqingSong wants to merge 1 commit into
Conversation
…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>
haven2world
approved these changes
May 19, 2026
Contributor
haven2world
left a comment
There was a problem hiding this comment.
Looks great! Thanks for the quick fix!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
DomIndexerImpl.reconcileSelectionwas losing theSelectionMarkerinserted by the firstreconcileNodeSelectioncall when handling a range that spans two text nodes. The second call's adjacent-marker cleanup loop absorbedmarker1if it ended up directly next to the second text node's segment (notably whenstartOffset == startContainer.nodeValue.length).setSelectionthen orphaned both markers and the selected segment never receivedisSelected.preserveMarker; the cleanup loops now skip that specific reference while still absorbing other adjacent stale markers.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— cleanyarn test:fast— 5840 passing (includes the new regression test)yarn b— build succeedsFixes #3341
🤖 Generated with Claude Code