From 371e4efde316c770627a4d93777aa74d3eae61f3 Mon Sep 17 00:00:00 2001 From: Hikari Date: Fri, 23 Jan 2026 14:36:39 -0800 Subject: [PATCH] fix: arrow keys navigate cursor when user has typed input - Added userHasTyped flag to track manual input vs history navigation - Arrow keys only navigate history when input is empty or from history - Clearing input re-enables history navigation Closes #58 --- src/lib/components/InputBar.svelte | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/components/InputBar.svelte b/src/lib/components/InputBar.svelte index 86d417c..bd819c5 100644 --- a/src/lib/components/InputBar.svelte +++ b/src/lib/components/InputBar.svelte @@ -38,6 +38,7 @@ let inputHistory = $state([]); let historyIndex = $state(-1); let tempInput = $state(""); + let userHasTyped = $state(false); // Track if user manually typed (vs history navigation) // Textarea resize state let textareaHeight = $state(48); @@ -112,6 +113,13 @@ }); function handleInputChange() { + // If input is empty, allow history navigation again + // Otherwise, mark that user has manually typed + if (inputValue === "") { + userHasTyped = false; + } else { + userHasTyped = true; + } // Reset history navigation when user types historyIndex = -1; tempInput = ""; @@ -156,6 +164,7 @@ addToHistory(message); historyIndex = -1; tempInput = ""; + userHasTyped = false; const wasCommand = await executeSlashCommand(); if (wasCommand) return; @@ -175,6 +184,7 @@ addToHistory(message); historyIndex = -1; tempInput = ""; + userHasTyped = false; isSubmitting = true; inputValue = ""; @@ -308,8 +318,9 @@ User: ${formattedMessage}`; } } - // Handle input history navigation (when command menu is closed) - if (event.key === "ArrowUp" && inputHistory.length > 0) { + // Handle input history navigation (when command menu is closed AND user hasn't typed) + // If user has typed something, let arrow keys navigate the cursor instead + if (event.key === "ArrowUp" && inputHistory.length > 0 && !userHasTyped) { event.preventDefault(); if (historyIndex === -1) { // Save current input before navigating history @@ -322,12 +333,13 @@ User: ${formattedMessage}`; return; } - if (event.key === "ArrowDown" && historyIndex >= 0) { + if (event.key === "ArrowDown" && historyIndex >= 0 && !userHasTyped) { event.preventDefault(); historyIndex--; if (historyIndex === -1) { // Restore the temp input when going back to current inputValue = tempInput; + userHasTyped = false; // Reset since we're back to empty/temp state } else { inputValue = inputHistory[historyIndex]; }