Skip to content

Commit 0e47cc9

Browse files
committed
feat: throttle input keydown events
1 parent 184f832 commit 0e47cc9

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

bun.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"fuse.js": "^7.1.0",
3434
"hosted-git-info": "^8.1.0",
3535
"jsdom": "^26.1.0",
36+
"lodash-es": "^4.17.21",
3637
"marked": "^15.0.12",
3738
"new-github-issue-url": "^1.1.0",
3839
"pathe": "^2.0.3",
@@ -58,6 +59,7 @@
5859
"@types/dompurify": "^3.2.0",
5960
"@types/hosted-git-info": "^3.0.5",
6061
"@types/jsdom": "^21.1.7",
62+
"@types/lodash-es": "^4.17.12",
6163
"@types/node": "^22.15.21",
6264
"@types/validate-npm-package-name": "^4.0.2",
6365
"@vitest/coverage-v8": "^3.1.4",

src/components/NpmPackageSearch.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { throttle } from "lodash-es";
23
import { resource, useMutationObserver, watch } from "runed";
34
import LucideLoaderCircle from "~icons/lucide/loader-circle";
45
import LucideSearch from "~icons/lucide/search";
@@ -78,7 +79,7 @@
7879
}
7980
}
8081
81-
function handleInputKeydown(event: KeyboardEvent) {
82+
let handleInputKeydown = throttle((event: KeyboardEvent) => {
8283
switch (event.key) {
8384
case "ArrowUp":
8485
event.preventDefault();
@@ -93,7 +94,7 @@
9394
useResult();
9495
return;
9596
}
96-
}
97+
}, 25);
9798
9899
function prevResult() {
99100
resultsCursor = mod(resultsCursor - 1, results.current.length);

0 commit comments

Comments
 (0)