Skip to content

Conversation

@ruhanicpatel
Copy link

@ruhanicpatel ruhanicpatel commented Dec 7, 2025

Description:
This PR addresses a bug where “Add selection to next find match” (Ctrl+D) did not work when regex find mode was enabled. It also adds automated tests to verify correct behavior in both regex and plain text search modes.

Context / Issue:
When using regex search in VSCode, adding a selection to the next find match failed (#5715). Users expect multi-cursor selections to work consistently whether regex is enabled or not.

Changes / Fix:

- MultiCursorSession updates:
- Fixed logic in addSelectionToNextFindMatch and addSelectionToPreviousFindMatch to properly handle regex search text.
- Ensured “add all matches to selection” works correctly with regex.

- Tests:
- Added multicursor.mock.test.ts covering:
- Adding selection to next match in regex mode.
- Adding selection to previous match in regex mode.
- Adding all matches to selection in regex mode.

- Documentation / Instructions:
- Instructions for running tests included.

Steps to Verify Fix:

  1. Open a file containing repeated patterns.
  2. Enable regex mode in the editor search tool.
  3. Press Ctrl+D (add selection to next match).
  4. Confirm that all regex matches are added as new cursors.
  5. Run the automated tests:
    npm run test-mock
  6. Confirm all tests pass.

Example Test:

const model = createTestModel('abc abc abc');
const editor = createTestEditor(model);
const session = new MultiCursorSession(editor, findController, true, 'abc', false, false, null);

session.addSelectionToNextFindMatch();
assert.deepEqual(editor.getSelections().map(s => s.getStartPosition().column), [1, 5]);

Notes:

  • Ensures consistent behavior between regex and plain text find modes.
  • Prevents regressions in multi-cursor selection behavior in future updates.

Related Issue: (#107090)

@ruhanicpatel
Copy link
Author

@microsoft-github-policy-service agree

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.

3 participants