Skip to content

Commit ac5decb

Browse files
committed
feat: add search to hotkeys list
1 parent e1ece5a commit ac5decb

3 files changed

Lines changed: 66 additions & 10 deletions

File tree

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "lineage",
33
"name": "Lineage",
4-
"version": "0.1.1-dev",
4+
"version": "0.2.0-dev",
55
"minAppVersion": "0.15.0",
66
"description": "Gingko-like writing experience.",
77
"author": "ycnmhd",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lineage",
3-
"version": "0.1.1-dev",
3+
"version": "0.2.0-dev",
44
"description": "",
55
"scripts": {
66
"dev": "node esbuild.config.mjs",

src/view/components/container/hotkeys/hotkeys.svelte

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,69 @@
11
<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
37
import Hotkey from './components/command.svelte';
48
import { getPlugin, getView } from 'src/view/components/container/context';
59
import {
610
detectConflictingHotkeys
711
} from 'src/view/actions/keyboard-shortcuts/helpers/keyboard-events/detect-conflicting-hotkeys';
812
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+
}
1339
</script>
1440

1541
<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>
1762
<div class="hotkeys-list">
1863
{#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}
2067
{/each}
2168
</div>
2269
<div class="note">
@@ -44,10 +91,19 @@
4491
padding: var(--size-4-2);
4592
}
4693
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+
}
47101
.title {
48102
font-size: 16px;
49103
color: var(--color-base-70);
50-
padding: 12px var(--size-4-2);
104+
}
105+
.search-input-container {
106+
width: 150px;
51107
}
52108
.note {
53109
font-size: 12px;

0 commit comments

Comments
 (0)