Skip to content

Fix Match Whole Word skipping overlapping matches#326447

Open
dobbydobap wants to merge 2 commits into
microsoft:mainfrom
dobbydobap:fix-291591-wholeword-overlap
Open

Fix Match Whole Word skipping overlapping matches#326447
dobbydobap wants to merge 2 commits into
microsoft:mainfrom
dobbydobap:fix-291591-wholeword-overlap

Conversation

@dobbydobap

Copy link
Copy Markdown
Contributor

Fixes #291591. Match Whole Word is applied as a post-filter on each regex match; when a candidate fails the boundary check, the search resumed at the end of that candidate, skipping any valid whole-word match that starts inside it (e.g. the trailing aa-aa in xaa-aa-aa, which grep -w finds). Now it advances one code point on a failed check so overlapping matches are considered. Added a regression test.

Copilot AI review requested due to automatic review settings July 18, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes whole-word search skipping overlapping candidates after a boundary-check failure.

Changes:

  • Advances rejected matches by one Unicode code point.
  • Adds regression coverage for issue #291591.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/editor/common/model/textModelSearch.ts Adjusts search progression after rejected matches.
src/vs/editor/test/common/model/textModelSearch.test.ts Adds overlapping-match regression test.

Comment on lines +551 to +552
// Not a whole-word match; advance one code point so overlapping whole-word matches aren't skipped.
this._searchRegex.lastIndex = matchStartIndex + (strings.getNextCodePoint(text, textLength, matchStartIndex) > 0xFFFF ? 2 : 1);
}

// Not a whole-word match; advance one code point so overlapping whole-word matches aren't skipped.
this._searchRegex.lastIndex = matchStartIndex + (strings.getNextCodePoint(text, textLength, matchStartIndex) > 0xFFFF ? 2 : 1);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both good catches, thanks. Fixed the case-sensitive simpleSearch path (_findMatchesInLine now advances one position instead of the full match length on a rejected whole-word candidate), and reset _prevMatchStartIndex/_prevMatchLength after the explicit advance so the end-of-line guard stays reserved for returned matches. Extended the regression test to cover the case-sensitive path and the aa-aa|aa in xaa-aa end-of-line case

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find with "Match Whole Word" misses valid occurrences

3 participants