Skip to content

Commit d4e590f

Browse files
authored
docs: rework keyboard shortcuts to focus search bar (#1854)
1 parent f630007 commit d4e590f

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

docs/src/pages/_layout.svelte

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
<script context="module">
2-
// Pressing these keys will focus the search bar.
3-
const FOCUS_KEYS = new Set(["/", "Metak"]);
4-
</script>
5-
61
<script>
72
import {
83
isActive,
@@ -47,7 +42,6 @@
4742
const deprecated = [];
4843
const new_components = [];
4944
50-
let keys = "";
5145
let value = "";
5246
let active = false;
5347
$: results = miniSearch.search(value).slice(0, 10);
@@ -72,25 +66,18 @@
7266

7367
<svelte:body
7468
on:keydown="{(e) => {
75-
keys += e.key;
76-
}}"
77-
on:keyup="{(e) => {
7869
if (active) return;
79-
80-
if (FOCUS_KEYS.has(keys)) {
81-
if (
82-
document.activeElement instanceof HTMLInputElement ||
83-
document.activeElement instanceof HTMLTextAreaElement
84-
) {
85-
// Exit early if an inputtable element is already focused.
86-
return;
87-
}
88-
70+
if (
71+
document.activeElement instanceof HTMLInputElement ||
72+
document.activeElement instanceof HTMLTextAreaElement
73+
) {
74+
// Exit early if an inputtable element is already focused.
75+
return;
76+
}
77+
if ((e.metaKey && e.key === 'k') || e.key === '/') {
8978
e.preventDefault();
9079
active = true;
9180
}
92-
93-
keys = '';
9481
}}" />
9582

9683
<Theme persist bind:theme="{$theme}">

0 commit comments

Comments
 (0)