Skip to content

Commit

Permalink
a different kind of autofocus?
Browse files Browse the repository at this point in the history
KTibow committed Dec 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f186878 commit 410f28f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Chat.svelte
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import stream from "./stream";
export let groqKey: string;
let textarea: HTMLTextAreaElement;
const getModel = async () => {
if (localStorage.model) return localStorage.model;
@@ -46,6 +47,13 @@
}
};
const maybeFocus = (e: KeyboardEvent) => {
const isAlphanumeric = /^[a-zA-Z0-9]$/.test(e.key);
if (e.target == document.body && isAlphanumeric && !e.ctrlKey) {
textarea.focus();
}
};
let conversation: { role: string; content: string }[] = [];
const searchParams = new URLSearchParams(window.location.search);
const q = searchParams.get("q");
@@ -54,6 +62,7 @@
}
</script>

<svelte:window on:keydown={maybeFocus} />
<button on:click={() => (conversation = [])}>
<Icon icon={iconTrash} width="1.5rem" height="1.5rem" />
</button>
@@ -75,10 +84,9 @@
textarea.value = "";
}}
>
<!-- svelte-ignore a11y_autofocus -->
<textarea
name="query"
autofocus
bind:this={textarea}
on:keydown={(e) => {
if (e.key == "Enter" && !e.shiftKey) {
e.currentTarget.form.requestSubmit();

0 comments on commit 410f28f

Please sign in to comment.