fix: Add selection to next Find match does not work with Regex Find Mode#322873
fix: Add selection to next Find match does not work with Regex Find Mode#322873pratheeknathani wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Ctrl+D (“Add Selection to Next Find Match”) when the Find widget is in regex mode by ensuring the multicursor session forwards the Find widget’s isRegex option to the model search APIs.
Changes:
- Thread
isRegexfrom the Find widget state intoMultiCursorSessionwhen the Find widget owns the search. - Use
this.isRegex(instead of hardcodedfalse) forfindNextMatch,findPreviousMatch, andfindMatches. - Add a regression test intended to validate
Ctrl+Dbehavior with regex search.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/editor/contrib/multicursor/browser/multicursor.ts | Propagates regex mode into multicursor find/selection expansion when the Find widget owns the search string. |
| src/vs/editor/contrib/multicursor/test/browser/multicursor.test.ts | Adds a regression test for Ctrl+D with regex search. |
| editor.setSelection(new Selection(1, 1, 1, 1)); | ||
| findController.getState().change({ searchString: 'a.c', isRegex: true, isRevealed: true }, false); | ||
|
|
There was a problem hiding this comment.
Good catch, thank you. You're right that with the default hasTextFocus: true the session took the selection-owned path, expanded the cursor's word, and searched literally, so the regex option was never exercised and the test passed regardless of the fix.
I've updated it to run with focus outside the editor so the find widget owns the search. I threaded an optional hasTextFocus through the local testMulticursor/testAddSelectionToNextFindMatchAction helpers (defaulting to the existing behavior for every other test) and pass hasTextFocus: false here, which makes MultiCursorSession.create take the find-widget-owned path.
I also kept the search string as the regex a.c: it matches abc on every line as a regex but matches nothing as a literal. So on the find-widget path, without forwarding isRegex the first findNextMatch returns null and the selections never expand (first assertion fails); with the fix it matches and passes. Reasoning through the create -> _beginSessionIfNeeded -> addSelectionToNextFindMatch -> findNextMatch flow, this should now genuinely exercise the regression. Happy to adjust if a maintainer spots anything I missed when CI runs the suite.
66d2e48 to
6ef786b
Compare
|
@microsoft-github-policy-service agree company="Microsoft" |
Summary
The "Add Selection to Next Find Match" (Ctrl+D) feature is implemented by
MultiCursorSessioninsrc/vs/editor/contrib/multicursor/browser/multicursor.ts. When the find widget owns the search (focus is in the find widget, the widget is revealed, and the search string is non-empty), the session uses the find...Root cause
The "Add Selection to Next Find Match" (Ctrl+D) feature is implemented by
MultiCursorSessioninsrc/vs/editor/contrib/multicursor/browser/multicursor.ts.When the find widget owns the search (focus is in the find widget, the widget is
revealed, and the search string is non-empty), the session uses the find widget's
search string and its
wholeWord/matchCaseoptions. However, the model lookupsin
_getNextMatch,_getPreviousMatch, andselectAllall passed theisRegexargument to
findNextMatch/findPreviousMatch/findMatchesas a hardcodedfalse. As a result, a regex pattern coming from the find widget was always treatedas literal text, so no further matches were found and no cursor was added.
What changed
File:
src/vs/editor/contrib/multicursor/browser/multicursor.tsisRegexfield toMultiCursorSession(constructor parameter).MultiCursorSession.create, passfindState.isRegexwhen the find widget ownsthe search, and
falsefor the selection-owned case (the search text there is theliteral selected text, so regex must stay off, which also matches the existing
isRegexOverride: FindOptionOverride.Falsebehavior for the disconnected case).falseisRegex argument withthis.isRegexin thefindNextMatch,findPreviousMatch, and the twofindMatchescalls.File:
src/vs/editor/contrib/multicursor/test/browser/multicursor.test.tsmode (Add selection to next Find match does not work with Regex Find Mode #107090)" that turns on regex mode in the find controller with pattern
a.cand verifies that each
Ctrl+Dadds the next regex match as a new selection.Issue
Fixes #107090
Issue: #107090
Diffstat
Testing
Ran the relevant tests and linter for the changed files while developing.
Kept the change minimal and focused on this one issue.
AI assistance
I used GitHub Copilot to help write parts of this change. I've reviewed and tested it myself, I understand what it does, and I'll follow up on any review feedback.