Skip to content

Commit 5056bb6

Browse files
committed
Settings: Fix key filter subset matching
1 parent 1fd540a commit 5056bb6

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

apps/desktop/src/lib/settings/sections/KeyboardShortcutsSection.svelte

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@
9292
cmds = cmds.filter((c) => matchedIds.has(c.id))
9393
}
9494
95-
// Filter by key search (exact match on effective shortcuts)
95+
// Filter by key search (subset match: filter's modifiers + key must all be present in shortcut)
9696
if (keySearchQuery.trim()) {
9797
cmds = cmds.filter((c) => {
9898
const shortcuts = getEffectiveShortcuts(c.id)
99-
return shortcuts.some((s) => s.toLowerCase().includes(keySearchQuery.toLowerCase()))
99+
return shortcuts.some((s) => keyFilterMatches(s, keySearchQuery))
100100
})
101101
}
102102
@@ -264,6 +264,34 @@
264264
}
265265
}
266266
267+
/** Check if a filter combo is a subset of a shortcut (all filter modifiers + key present in shortcut) */
268+
const macModifierSet = new Set(['', '', '', ''])
269+
const nonMacModifierSet = new Set(['Ctrl', 'Alt', 'Shift', 'Super'])
270+
271+
function splitCombo(combo: string): { mods: Set<string>; key: string } {
272+
if (isMacOS()) {
273+
const chars = Array.from(combo)
274+
const mods = new Set(chars.filter((ch) => macModifierSet.has(ch)))
275+
const key = chars.filter((ch) => !macModifierSet.has(ch)).join('')
276+
return { mods, key }
277+
}
278+
const parts = combo.split('+')
279+
const mods = new Set(parts.filter((p) => nonMacModifierSet.has(p)))
280+
const key = parts.filter((p) => !nonMacModifierSet.has(p)).join('+')
281+
return { mods, key }
282+
}
283+
284+
function keyFilterMatches(shortcut: string, filter: string): boolean {
285+
const s = splitCombo(shortcut)
286+
const f = splitCombo(filter)
287+
288+
for (const mod of f.mods) {
289+
if (!s.mods.has(mod)) return false
290+
}
291+
if (f.key && s.key.toLowerCase() !== f.key.toLowerCase()) return false
292+
return true
293+
}
294+
267295
// Key filter field: track modifiers and build combo string
268296
function formatModifiers(event: KeyboardEvent): string {
269297
const parts: string[] = []

0 commit comments

Comments
 (0)