|
1 | 1 | <script lang="ts"> |
2 | | - import { createCommands } from '../../../actions/keyboard-shortcuts/helpers/create-commands'; // Import the PluginCommand type |
| 2 | + import { |
| 3 | + createCommands, |
| 4 | + hotkeysLang, |
| 5 | + LineageCommandName |
| 6 | + } from '../../../actions/keyboard-shortcuts/helpers/create-commands'; // Import the PluginCommand type |
3 | 7 | import Hotkey from './components/command.svelte'; |
4 | 8 | import { getPlugin, getView } from 'src/view/components/container/context'; |
5 | 9 | import { |
6 | 10 | detectConflictingHotkeys |
7 | 11 | } from 'src/view/actions/keyboard-shortcuts/helpers/keyboard-events/detect-conflicting-hotkeys'; |
8 | 12 |
|
9 | | - const plugin = getPlugin() |
10 | | - const commands = createCommands(plugin); |
11 | | - const view = getView() |
12 | | - const usedHotkeys = detectConflictingHotkeys(plugin, Object.values(commands), view.containerEl) |
| 13 | + const plugin = getPlugin(); |
| 14 | + const commands = createCommands(plugin); |
| 15 | + const view = getView(); |
| 16 | + const usedHotkeys = detectConflictingHotkeys( |
| 17 | + plugin, |
| 18 | + Object.values(commands), |
| 19 | + view.containerEl, |
| 20 | + ); |
| 21 | + let searchTerm = ''; |
| 22 | +
|
| 23 | + const entries = Object.keys(commands).map((k) => [ |
| 24 | + hotkeysLang[k as LineageCommandName].toLowerCase(), |
| 25 | + k, |
| 26 | + ]); |
| 27 | + let matches = new Set(); |
| 28 | + $: { |
| 29 | + matches = new Set(); |
| 30 | + if (searchTerm) { |
| 31 | + const search_term = searchTerm.toLowerCase(); |
| 32 | + for (const [name, key] of entries) { |
| 33 | + if (name.includes(search_term)) { |
| 34 | + matches.add(key); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
13 | 39 | </script> |
14 | 40 |
|
15 | 41 | <div class="sidebar"> |
16 | | - <span class="title">Keyboard shortcuts</span> |
| 42 | + <div class="front"> |
| 43 | + <span class="title">Keyboard shortcuts </span> |
| 44 | + <div class="search-input-container"> |
| 45 | + <input |
| 46 | + bind:value={searchTerm} |
| 47 | + class="search-input" |
| 48 | + enterkeyhint="search" |
| 49 | + placeholder={'Filter'} |
| 50 | + spellcheck="false" |
| 51 | + type="search" |
| 52 | + /> |
| 53 | + <div |
| 54 | + aria-label={'Clear'} |
| 55 | + class="search-input-clear-button" |
| 56 | + on:click={() => { |
| 57 | + searchTerm = ''; |
| 58 | + }} |
| 59 | + ></div> |
| 60 | + </div> |
| 61 | + </div> |
17 | 62 | <div class="hotkeys-list"> |
18 | 63 | {#each Object.entries(commands) as [key, command]} |
19 | | - <Hotkey {key} {command} {usedHotkeys}/> |
| 64 | + {#if !matches.size || matches.has(key)} |
| 65 | + <Hotkey {key} {command} {usedHotkeys} /> |
| 66 | + {/if} |
20 | 67 | {/each} |
21 | 68 | </div> |
22 | 69 | <div class="note"> |
|
44 | 91 | padding: var(--size-4-2); |
45 | 92 | } |
46 | 93 |
|
| 94 | + .front { |
| 95 | + display: flex; |
| 96 | + justify-content: space-between; |
| 97 | + align-items: center; |
| 98 | + width: 100%; |
| 99 | + padding: 12px var(--size-4-2); |
| 100 | + } |
47 | 101 | .title { |
48 | 102 | font-size: 16px; |
49 | 103 | color: var(--color-base-70); |
50 | | - padding: 12px var(--size-4-2); |
| 104 | + } |
| 105 | + .search-input-container { |
| 106 | + width: 150px; |
51 | 107 | } |
52 | 108 | .note { |
53 | 109 | font-size: 12px; |
|
0 commit comments