|
92 | 92 | cmds = cmds.filter((c) => matchedIds.has(c.id)) |
93 | 93 | } |
94 | 94 |
|
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) |
96 | 96 | if (keySearchQuery.trim()) { |
97 | 97 | cmds = cmds.filter((c) => { |
98 | 98 | const shortcuts = getEffectiveShortcuts(c.id) |
99 | | - return shortcuts.some((s) => s.toLowerCase().includes(keySearchQuery.toLowerCase())) |
| 99 | + return shortcuts.some((s) => keyFilterMatches(s, keySearchQuery)) |
100 | 100 | }) |
101 | 101 | } |
102 | 102 |
|
|
264 | 264 | } |
265 | 265 | } |
266 | 266 |
|
| 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 | +
|
267 | 295 | // Key filter field: track modifiers and build combo string |
268 | 296 | function formatModifiers(event: KeyboardEvent): string { |
269 | 297 | const parts: string[] = [] |
|
0 commit comments