Skip to content

refactor: share the find input toggle navigation - #329128

Merged
Raymond Zhao (rzhao271) merged 2 commits into
microsoft:mainfrom
Xaena53:dedupe-findinput-toggle-navigation
Aug 6, 2026
Merged

refactor: share the find input toggle navigation#329128
Raymond Zhao (rzhao271) merged 2 commits into
microsoft:mainfrom
Xaena53:dedupe-findinput-toggle-navigation

Conversation

@Xaena53

Copy link
Copy Markdown
Contributor

Fixes #199892

FindInput and ReplaceInput each carried their own copy of the arrow-key / Escape handling that moves focus between the toggles of a find input. The two blocks were identical apart from how the toggle elements are collected — FindInput resolves them through getToggleDomNodes(), ReplaceInput captures [this.preserveCase.domNode] up front.

This extracts the block into navigateToggles in findInputToggles.ts and calls it from both widgets. The extracted body is unchanged from the code that was removed; only this.getToggleDomNodes(), this.domNode and this.inputBox.focus() became parameters, so the diff should read as a straight move.

One detail worth calling out: the toggles are passed as a callback rather than as an array. FindInput only called getToggleDomNodes() after the key check, so passing the array eagerly would have resolved the toggles on every keystroke in the widget. The callback keeps the original laziness, and there is a test covering it.

How to test

Open the editor find widget (Ctrl+F), move focus into the toggles (Match Case / Match Whole Word / Use Regular Expression) and use Left/Right to move between them and Escape to go back to the input. The replace input's Preserve Case toggle behaves the same way.

Verification

Added src/vs/base/test/browser/ui/findinput/findInputToggles.test.ts covering wrap-around in both directions, Escape returning focus to the input, focus outside the toggles being ignored, and the lazy resolution described above.

node test/unit/browser/index.js --run src/vs/base/test/browser/ui/findinput/findInputToggles.test.ts --browser chromium
  5 passing

node test/unit/browser/index.js --runGlob "vs/base/test/browser/**/*.test.js" --browser chromium
  511 passing

node test/unit/browser/index.js --runGlob "vs/editor/contrib/find/**/*.test.js" --browser chromium
  76 passing

node test/unit/browser/index.js --runGlob "vs/workbench/contrib/search/**/*.test.js" --browser chromium
  68 passing

tsc --noEmit -p src/tsconfig.json and eslint on the touched files are both clean.

I was not able to run a full desktop build locally — the native modules need the Spectre-mitigated MSVC libraries, which my toolchain is missing — so the keyboard behaviour above is covered by the unit tests rather than by a manual pass in a built VS Code.

`FindInput` and `ReplaceInput` each carried their own copy of the
arrow-key/escape handling used to move focus between the toggles of a
find input. The two blocks were identical apart from how the toggle
elements are collected.

Extract the block into `navigateToggles` in findInputToggles.ts and call
it from both widgets. The toggles are passed as a callback so that they
keep being resolved only once one of the handled keys is pressed, as
`FindInput` did before.

Fixes microsoft#199892

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 5, 2026 08:37

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

Refactors find/replace toggle keyboard navigation into a shared helper, resolving #199892 without changing behavior.

Changes:

  • Extracts arrow-key and Escape handling into navigateToggles.
  • Reuses the helper in FindInput and ReplaceInput.
  • Adds focused tests for navigation, focus restoration, and lazy toggle resolution.

Reviewed changes

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

File Description
src/vs/base/browser/ui/findinput/findInputToggles.ts Adds the shared navigation helper.
src/vs/base/browser/ui/findinput/findInput.ts Uses the shared helper for find toggles.
src/vs/base/browser/ui/findinput/replaceInput.ts Uses the shared helper for Preserve Case.
src/vs/base/test/browser/ui/findinput/findInputToggles.test.ts Tests navigation and lazy resolution.
@Xaena53

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@rzhao271
Raymond Zhao (rzhao271) merged commit fec2ccd into microsoft:main Aug 6, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants