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]; }