Skip to content

Commit

Permalink
feat: improve UX on keyboard events
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Jun 27, 2024
1 parent a3ad4e6 commit 23b3dd6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
let push: (source: string) => Promise<void>;
onMount(async () => {
history.unshift(...(JSON.parse(localStorage.getItem("console-history") || "[]") as string[]).slice(0, 200));
history.unshift(...(JSON.parse(localStorage.getItem("console-history") || "[]") as string[]));
inputRef.focus();
});
Expand Down Expand Up @@ -77,7 +77,7 @@
function pushHistory(source: string) {
if (source.trim() && source !== history[0]) {
history.unshift(source);
localStorage.setItem("console-history", JSON.stringify(history));
localStorage.setItem("console-history", JSON.stringify(history.slice(0, 200)));
}
}
Expand All @@ -104,8 +104,10 @@
};
const onKeyDown: KeyboardEventHandler<Document> = (event) => {
if (!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey && event.key.length === 1)
if (!event.ctrlKey && !event.metaKey && !event.altKey && event.key.length === 1)
inputRef.focus();
else if (document.activeElement !== inputRef)
return;
switch (event.key) {
case "ArrowUp": {
Expand Down

0 comments on commit 23b3dd6

Please sign in to comment.