Skip to content

test(find): pin where a mark lands when whitespace collapses - #988

Merged
PathGao merged 1 commit into
masterfrom
test/find-mark-offsets
Oct 20, 2026
Merged

PathGao merged 1 commit into
masterfrom
test/find-mark-offsets

Conversation

@PathGao

@PathGao PathGao commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

What this is

A follow-up to #984. findText.ts works out each node's drawn text with one replace(/\s+/g, ' ') and, for the nodes a match reaches, the offsets back into the node with a separate loop. The two passes encode the same collapse rule. If they drifted apart, the highlight would land on the wrong characters while the match count stayed right, and the existing whitespace test only checked the count.

The new test asserts the marked text for collapsed whitespace runs, a leading space dropped after a node that already ends in one, and text after a visible <br>.

Tests

Two drifts were introduced in offsetsOf in turn: ignoring dropLead, and not collapsing whitespace. Each turns the new test red while the other 8 stay green.

Verification

npm run check
npm run test:vitest

513 vitest tests pass. Test-only change.

findText.ts works out the drawn text with one replace and the offsets back into each node with a separate loop. The existing whitespace test only counted matches, so the two could drift apart and put the highlight on the wrong characters while staying green. This asserts the marked text for collapsed runs, a dropped leading space and text after a visible break.
@PathGao
PathGao merged commit 3b320a3 into master Oct 20, 2026
4 checks passed
@PathGao
PathGao deleted the test/find-mark-offsets branch October 20, 2026 14:13
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.

1 participant