| 174 | } |
| 175 | |
| 176 | function filteredFor( |
| 177 | query: string, |
| 178 | list: Map<string, KeybindMeta>, |
| 179 | grouped: Map<KeybindGroup, string[]>, |
| 180 | keybind: (id: string) => string, |
| 181 | ) { |
| 182 | const value = query.toLowerCase().trim() |
| 183 | if (!value) return grouped |
| 184 | |
| 185 | const out = new Map<KeybindGroup, string[]>() |
| 186 | for (const group of GROUPS) out.set(group, []) |
| 187 | |
| 188 | const items = Array.from(list.entries()).map(([id, meta]) => ({ |
| 189 | id, |
| 190 | title: meta.title, |
| 191 | group: meta.group, |
| 192 | keybind: keybind(id), |
| 193 | })) |
| 194 | |
| 195 | const results = fuzzysort.go(value, items, { |
| 196 | keys: ["title", "keybind"], |
| 197 | threshold: -10000, |
| 198 | }) |
| 199 | |
| 200 | for (const result of results) { |
| 201 | const ids = out.get(result.obj.group) |
| 202 | if (!ids) continue |
| 203 | ids.push(result.obj.id) |
| 204 | } |
| 205 | |
| 206 | return out |
| 207 | } |
| 208 | |
| 209 | function useKeyCapture(input: { |
| 210 | active: () => string | null |