Skip to content

fix: Add selection to next Find match does not work with Regex Find Mode#322873

Open
pratheeknathani wants to merge 1 commit into
microsoft:mainfrom
pratheeknathani:fix-107090
Open

fix: Add selection to next Find match does not work with Regex Find Mode#322873
pratheeknathani wants to merge 1 commit into
microsoft:mainfrom
pratheeknathani:fix-107090

Conversation

@pratheeknathani

Copy link
Copy Markdown

Summary

The "Add Selection to Next Find Match" (Ctrl+D) feature is implemented by MultiCursorSession in src/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
MultiCursorSession in src/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 / matchCase options. However, the model lookups
in _getNextMatch, _getPreviousMatch, and selectAll all passed the isRegex
argument to findNextMatch / findPreviousMatch / findMatches as a hardcoded
false. As a result, a regex pattern coming from the find widget was always treated
as literal text, so no further matches were found and no cursor was added.

What changed

File: src/vs/editor/contrib/multicursor/browser/multicursor.ts

  • Added an isRegex field to MultiCursorSession (constructor parameter).
  • In MultiCursorSession.create, pass findState.isRegex when the find widget owns
    the search, and false for the selection-owned case (the search text there is the
    literal selected text, so regex must stay off, which also matches the existing
    isRegexOverride: FindOptionOverride.False behavior for the disconnected case).
  • Replaced the hardcoded false isRegex argument with this.isRegex in the
    findNextMatch, findPreviousMatch, and the two findMatches calls.

File: src/vs/editor/contrib/multicursor/test/browser/multicursor.test.ts

Issue

Fixes #107090

Issue: #107090

Diffstat

.../contrib/multicursor/browser/multicursor.ts | 13 +++++-----
 .../multicursor/test/browser/multicursor.test.ts | 30 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 6 deletions(-)

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.

Copilot AI review requested due to automatic review settings June 25, 2026 05:04

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

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 isRegex from the Find widget state into MultiCursorSession when the Find widget owns the search.
  • Use this.isRegex (instead of hardcoded false) for findNextMatch, findPreviousMatch, and findMatches.
  • Add a regression test intended to validate Ctrl+D behavior 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.

Comment on lines +294 to +296
editor.setSelection(new Selection(1, 1, 1, 1));
findController.getState().change({ searchString: 'a.c', isRegex: true, isRevealed: true }, false);

@pratheeknathani pratheeknathani Jun 25, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

@pratheeknathani

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

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.

Add selection to next Find match does not work with Regex Find Mode

3 participants