Skip to content

[Keyboard Manager] Search, filter and bulk-delete for the remapping list - #49287

Merged
Niels Laute (niels9001) merged 6 commits into
microsoft:mainfrom
MasaYan24:feature/kbm-search-filter
Sep 2, 2026
Merged

Niels Laute (niels9001) merged 6 commits into
microsoft:mainfrom
MasaYan24:feature/kbm-search-filter

Conversation

@MasaYan24

@MasaYan24 takahashi (MasaYan24) commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Adds a search / filter / bulk-delete bar to the Keyboard Manager editor so that large remapping lists stay navigable. Once you accumulate many remaps the single flat list becomes hard to scan; this adds lightweight ways to narrow it down and to clean it up.

This is editor-only — the Keyboard Manager engine and the on-disk configuration schema are untouched. Filtering is a pure view concern and is never persisted.

Addresses #28434 ("Search in keyboard manager").

Demo

Muted screen recording with on-screen captions:

49287_final_v3.mp4

It walks through: text search → the Win / Ctrl / Alt / Shift modifier toggles (OR within a group, AND across categories, including combining Ctrl + Alt) → the app filter → the "no results" empty state → Select mode → multi-select → Cancel → Delete selected → confirm → the rows are removed.

Detailed Description of the PR

A filter bar is added above the mapping list:

  • Text search — real-time, case-insensitive substring match over each row's key names, target (text / URL / program path) and target app.
  • Modifier toggles (Win / Ctrl / Alt / Shift) — a row matches if its trigger contains that modifier. Classification is done on the raw virtual-key codes, so it is independent of the display language. Multiple toggles combine with OR (Win + Ctrl shows the Win or Ctrl rows).
  • App filter — All apps / Global only / one entry per distinct target app.
  • The categories above combine with AND. When nothing matches, a dedicated "no results" state is shown with a Clear filters action, kept distinct from the normal empty state.
  • Multi-select + bulk delete — a Select toggle turns on multi-selection across all sections; Delete selected (n) removes them after a confirmation dialog. Only the currently visible (filtered) rows can be selected, so rows hidden by a filter can never be deleted by accident.

Implementation notes

  • Each section's list is already a data-bound ListView over an ObservableCollection. Those bound collections become filtered views over new backing lists; ApplyFilter() rebuilds them. Section visibility already keys off .Count, so filtered-empty sections collapse for free.
  • Rows now carry their raw trigger VK codes and a precomputed lowercased search string.
  • Bulk delete reuses the existing per-row delete handlers; no new deletion path.

PR Checklist

  • Closes: Search in keyboard manager #28434
  • Communication: I've discussed this with core contributors in the issue.
  • Tests: Made sure tests pass and, if applicable, added new relevant tests. (Editor-only UI change; validated by building and manual testing.)
  • Localization: All end-user-facing strings are in the .resw resources.
  • Dev docs: N/A
  • New binaries: N/A
  • Documentation updated: N/A (no doc changes needed)

Validation Steps Performed

  • Built KeyboardManagerEditorUI (Debug/x64) — clean, analyzers/StyleCop green.
  • Manually exercised search, each modifier toggle (incl. OR combinations), the app filter, combined AND filtering, the no-results/clear state, and multi-select bulk delete against a real ~80-entry configuration.

Draft: opened for discussion on #28434.

@zadjii-msft

Copy link
Copy Markdown
Member

Please add a screen recording of this running, thanks!

@zadjii-msft Mike Griese (zadjii-msft) added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 14, 2026
@MuyuanMS

Copy link
Copy Markdown
Contributor

Closing the PR for now as it's pending author response for too long. You can always reopen and continue on it.

@MasaYan24

takahashi (MasaYan24) commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews on this one — and sorry for the delay on the recording. The demo you and Mike Griese (@zadjii-msft) asked for is ready (below), so this is unblocked.

One snag: I can't reopen this from my side — GitHub refuses author-reopen after the auto-close (both the UI button and the API). Muyuan Li (@MuyuanMS) / Niels Laute (@niels9001), could you reopen it? If you'd rather I open a fresh PR that supersedes this one, just say the word and I'll do that instead.

The branch is up to date on my fork (MasaYan24:feature/kbm-search-filter) with the demo behaviour plus a few list-editor fixes folded in:

  • Select-mode crash — leaving multi-select mode (or finishing a bulk delete) accessed ListView.SelectedItems after the mode had flipped to None, which throws and took the panel down. The selection is now cleared while the lists are still Multiple, and every SelectedItems access is guarded. The Select toggle also becomes Cancel while active, so there's always a visible way out of selection mode.
  • Toggle silently flipping OFF on list refresh — container recycling (heavy during search / filter / bulk-delete reloads) re-raised Toggled on recycled rows and flipped the wrong entry's persisted active state; the handler now ignores recycle/binding-induced events.
  • "Add new remapping" moved into the list toolbar — it was a page-level row above the filter bar; it's really a list-level action.

This stays editor-only — the engine and the on-disk config schema are untouched, and filtering is never persisted.

The recording (muted, on-screen captions) walks through: text search → the Win / Ctrl / Alt / Shift modifier toggles (OR within a group, AND across categories, including combining Ctrl + Alt) → the app filter → the "no results" empty state → Select mode → multi-select → Cancel → Delete selected → confirm → the rows are removed.

Screen recording 👇

49287_final_v3.mp4
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
@MuyuanMS Muyuan Li (MuyuanMS) removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 6, 2026
@MasaYan24

Copy link
Copy Markdown
Contributor Author

Thanks for reopening it, Muyuan Li (@MuyuanMS) — much appreciated! 🙏

I'm keeping this one in Draft for now and will mark it Ready for review once #49136 lands, just to keep the review order clean. In the meantime the demo recording is posted above and CI is green here (license/cla passing), so there's nothing blocking on my side.

@MasaYan24
takahashi (MasaYan24) marked this pull request as ready for review August 31, 2026 11:23
@github-actions github-actions Bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 31, 2026
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

🧭 PR intake

Visual evidence: Required — The pull request changes product UI files, so reviewers need to see the visible result. Visual evidence was detected in the PR description.

Recommendation

Link the issue this PR fixes using a closing keyword such as Closes #123.

✅ Ready for review

This PR passed the automated intake checks and is ready for maintainer review.

Automated PR intake; PowerToys maintainers make final decisions.

@niels9001

Copy link
Copy Markdown
Collaborator

takahashi (@MasaYan24) few conflicts popped up. If you can handle those conflicts we can start merging this :)! Amazing work!

I do think we need some UI changes to make sure it's consistent with other Fluent UIs and to ensure we meet Accessibility criteria, but I can handle those once this is merged in.

…pping list

Add a filter bar above the mapping list so large remap sets stay navigable
(this machine's config has 84 entries). Addresses microsoft#28434.

- Text search over key names, target text/URL/program path and app (real-time).
- Modifier toggles (Win/Ctrl/Alt/Shift) classify rows by raw VK code, so the
  filter is locale-independent; multiple toggles combine with OR.
- App filter (All apps / Global only / each target app).
- Filter categories combine with AND; a dedicated "no results" state offers a
  Clear action, distinct from the empty state.
- Multi-select mode + "Delete selected (n)" with a confirmation dialog; only the
  currently visible (filtered) rows can be selected, so hidden rows stay safe.

Implementation keeps the engine and config schema untouched: each section's bound
ObservableCollection becomes a filtered view over a backing list, and ApplyFilter()
rebuilds the views. Rows carry their raw trigger VK codes and a precomputed search
string; existing per-row delete handlers are reused for bulk delete.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… refresh

The per-row enable/disable ToggleSwitch binds IsOn via a OneTime x:Bind to
IsActive and handles Toggled without guarding against non-user changes.
ListView container recycling (heavy during search/filter, bulk-delete reloads
and scrolling of a long list) re-applies the binding to the recycled-in item,
which raises Toggled. The handler then calls Enable/DisableShortcut, whose
non-idempotent ToggleShortcutKeyMappingActiveState flips the wrong entry's
persisted active state, so unrelated shortcuts silently switch OFF.

Guard the handler so it only acts when the control state actually diverges
from the model (IsOn != IsActive), ignoring recycle/binding-induced events.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…lbar

"Add new remapping" sat on its own row at the top of the page, above the
search / filter / bulk-select bar, reading as a page-level action. It is really a
list-level action, so move it to the leading (left) edge of the list toolbar,
aligned with the list below, and drop the now-empty top row.

The button is kept outside the search/filter cluster (which hides when there are no
mappings) so the first remapping can still be added from the empty state, and is
given the accent style so the primary "create" action stands out among the neutral
filter controls.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EJG9NHHEkEgFmp9W7djrnt
…clear exit

Leaving multi-select mode crashed the settings panel: flipping IsSelectionMode
off switches every list's SelectionMode to None, and the follow-up
ClearAllSelections()/UpdateSelectedCount() then touch ListView.SelectedItems,
which is only valid in Multiple mode and throws otherwise. The same path also
fired after a bulk delete.

- Clear the selection while the lists are still in Multiple mode, and guard both
  SelectedItems.Clear() and .Count behind a SelectionMode check so the selection
  housekeeping is safe in any mode.
- The Select toggle now reads "Cancel" (with an "Exit selection mode" tooltip)
  while active, so there is always a visible way out of selection mode instead of
  a stuck-looking pressed "Select" button.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EJG9NHHEkEgFmp9W7djrnt
Run the repo's XAML Styler over the search/filter toolbar markup so it passes
the "Verify XAML formatting" CI step: reflow the "Add new remapping" comment to
the styler's multi-line form and normalize attribute ordering on two toolbar
StackPanels. Formatting only; no markup or behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EJG9NHHEkEgFmp9W7djrnt
@MasaYan24

Copy link
Copy Markdown
Contributor Author

Thanks Niels Laute (@niels9001)! 🙏 Conflicts are resolved — this is now rebased onto the latest main and shows as mergeable again.

The conflicts came from #49136 (alone/tap remap) landing in the same editor files. Both sides only added new members side by side, so the resolution keeps both: Condition / IsAlone from the alone feature alongside TriggerKeyCodes / SearchableText from this PR.

Verified locally after the rebase:

  • KBM editor builds clean (Release x64, 0 warnings)
  • applyXamlStyling format check passes on MainPage.xaml

And sounds great re: the Fluent/accessibility polish — happy for you to take that once this is merged in. Thanks again for the review!

@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams Needs-Team-Response An issue author responded so the team needs to follow up and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Aug 31, 2026
@niels9001

Copy link
Copy Markdown
Collaborator

takahashi (@MasaYan24) great work!! Love the new filters!

I've passed this along to the design team, they had some feedback that the existing implementation might not scale and is not inline with the Fluent Design guidance. Based on their feedback I have made some changes to your PR and created a PR against it: MasaYan24#1

Can we get that one merged? Other than that I think it's good to go!!

kbm

@niels9001 Niels Laute (niels9001) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See comment

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MasaYan24

Copy link
Copy Markdown
Contributor Author

Merged! 🎉 Thanks a lot Niels Laute (@niels9001) — and thanks for looping in the design team.

The redesign is in on feature/kbm-search-filter (rebased, so the branch history stays linear). I really like where it landed: the search box in the title bar with Ctrl+F, the modifier/application filters collected into a single flyout, and the icon-only selection actions all read much better than what I had, and it scales far better as the filter set grows.

Verified locally after the merge:

  • KeyboardManagerEditorUI builds clean (Release x64, 0 warnings, 0 errors)
  • applyXamlStyling.ps1 -Main leaves the KBM XAML untouched (no formatting drift)

Could you re-review / dismiss the change request when you get a chance? Happy to pick up anything else you spot.

@niels9001
Niels Laute (niels9001) enabled auto-merge (squash) September 2, 2026 21:49
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
@niels9001
Niels Laute (niels9001) merged commit 9c20fbb into microsoft:main Sep 2, 2026
9 of 13 checks passed
@khmyznikov

Copy link
Copy Markdown
Contributor

takahashi (@MasaYan24) could you make a follow-up PR to add a UI test for this new feature? You could use the ui-tests-migration and ui-tests-local-vm skills to make it easier.

@MasaYan24

Copy link
Copy Markdown
Contributor Author

Sure thing, Gleb Khmyznikov (@khmyznikov) ??done: #50352

It turned out KeyboardManager.UITests is already on the Microsoft.PowerToys.UITest.Next / winappcli harness, so it is a new test class in the existing project rather than a migration. Two tests: one walks Ctrl+F search, the modifier toggles, the application filter and the no-results state (and asserts none of it touches the stored profile), the other covers selection mode and bulk delete end to end, including persistence across an editor restart.

One caveat I called out in the PR: I could not run the suite locally (it resets the real Keyboard Manager configuration and takes over the desktop, and I have no isolated VM here), so it is compile-verified only. If someone can start /azp run on it I will happily fix whatever comes back red.

Muyuan Li (MuyuanMS) pushed a commit that referenced this pull request Sep 11, 2026
…lete (#50352)

## Summary

Follow-up to #49287, requested by @khmyznikov: UI tests for the
remapping-list search, filters and bulk delete that shipped in that PR.

`KeyboardManager.UITests` is already on the
`Microsoft.PowerToys.UITest.Next` / winappcli harness, so this adds a
test class to the existing project rather than scaffolding a new one. No
product code changes.

## What the tests cover

**`KeyboardManager.Editor.SearchAndFilter`**
- <kbd>Ctrl</kbd>+<kbd>F</kbd> moves focus to the title-bar search box
and the typed text narrows the list
- **Clear filters** in the filter flyout restores the full list
- The **Ctrl** and **Alt** modifier toggles each narrow the list to
their own mapping
- The application filter hides app-specific mappings under **Global
only**
- A search with no matches shows the dedicated **no-results** state, and
its *Clear filters* button recovers from it
- Searching and filtering never touch the persisted profile

**`KeyboardManager.Editor.BulkDelete`**
- Selection mode turns the toolbar button into the **Cancel** affordance
- Two selected rows produce a `Delete selected (2)` label on an enabled
bulk-delete button
- Confirming the dialog removes **exactly** the two selected mappings
and leaves the other two untouched
- The editor leaves selection mode afterwards, and the deletion survives
an editor restart

## Note on the seeded profile

The seeded mappings deliberately use function keys (F13-F17) as their
trigger keys. The Keyboard Manager engine is live while these tests run,
so a remap on an ordinary letter would rewrite the characters the test
types into the search box.

## Validation

- `KeyboardManager.UITests` builds clean (x64 Debug); the new file
produces no analyzer warnings.
- I have **not** executed the suite locally. These tests reset the real
`%LOCALAPPDATA%\Microsoft\PowerToys` Keyboard Manager configuration and
take over the interactive desktop, and I do not have an isolated
desktop/VM available on this machine. Could a maintainer kick off `/azp
run` so the `Resolve affected UI test projects` job picks them up? Happy
to iterate on anything that comes back red.

## Checklist

- [x] **Closes:** n/a — follow-up to #49287
- [x] **Communication:** requested by @khmyznikov in
#49287 (comment)
- [x] **Tests:** this PR *is* the tests; no product code is changed
- [x] **Localization:** no new user-facing strings
- [x] **Dev docs:** no behaviour change to document

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Team-Response An issue author responded so the team needs to follow up Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams Product-Keyboard Manager Ready for review

5 participants