From 153387bbb4ed131d2809fe46212734d728d17524 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Fri, 24 Oct 2025 12:49:59 +0100 Subject: [PATCH] Add automatic focus to prompt input when typing --- src/components/prompt-input.tsx | 36 ++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/components/prompt-input.tsx b/src/components/prompt-input.tsx index 5869a029..1258937a 100644 --- a/src/components/prompt-input.tsx +++ b/src/components/prompt-input.tsx @@ -1,4 +1,4 @@ -import { createSignal, Show, onMount, For } from "solid-js" +import { createSignal, Show, onMount, For, onCleanup } from "solid-js" import AgentSelector from "./agent-selector" import ModelSelector from "./model-selector" import FilePicker from "./file-picker" @@ -114,6 +114,40 @@ export default function PromptInput(props: PromptInputProps) { onMount(async () => { const loaded = await getHistory(props.instanceFolder) setHistory(loaded) + + const handleGlobalKeyDown = (e: KeyboardEvent) => { + const activeElement = document.activeElement as HTMLElement + + const isInputElement = + activeElement?.tagName === "INPUT" || + activeElement?.tagName === "TEXTAREA" || + activeElement?.tagName === "SELECT" || + activeElement?.isContentEditable + + if (isInputElement) return + + const isModifierKey = e.ctrlKey || e.metaKey || e.altKey + if (isModifierKey) return + + const isSpecialKey = + e.key === "Escape" || + e.key === "Tab" || + e.key === "Enter" || + e.key.startsWith("Arrow") || + e.key === "Backspace" || + e.key === "Delete" + if (isSpecialKey) return + + if (e.key.length === 1 && textareaRef && !props.disabled) { + textareaRef.focus() + } + } + + document.addEventListener("keydown", handleGlobalKeyDown) + + onCleanup(() => { + document.removeEventListener("keydown", handleGlobalKeyDown) + }) }) function handleKeyDown(e: KeyboardEvent) {