From e4860171c7f5fb8fff8f96764282fa090734bd1e Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 19 Mar 2025 22:10:51 -0700 Subject: [PATCH 1/2] Revert "feat(editor): implement up/down arrow key history navigation for edit mode" This reverts commit fc92d55c8c414a0fdb0350f44e4e2f692fc40f2c. --- gui/src/components/mainInput/TipTapEditor.tsx | 10 +- gui/src/hooks/useInputHistory.ts | 112 +++++------------- 2 files changed, 33 insertions(+), 89 deletions(-) diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 7c1ace735..046da1021 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -301,9 +301,7 @@ function TipTapEditor(props: TipTapEditorProps) { } } - // Ensure we're using the correct history key - chat for main input, edit for edit mode - const historyKey = props.historyKey === 'edit' ? 'edit' : 'chat'; - const { prevRef, nextRef, addRef } = useInputHistory(historyKey); + const { prevRef, nextRef, addRef } = useInputHistory(props.historyKey); const editor: Editor | null = useEditor({ extensions: [ @@ -662,9 +660,9 @@ function TipTapEditor(props: TipTapEditorProps) { return; } - // Always add to input history regardless of input type - // This ensures that both chat and edit modes maintain their own history - addRef.current(json); + if (props.isMainInput) { + addRef.current(json); + } props.onEnter(json, modifiers, editor); }, diff --git a/gui/src/hooks/useInputHistory.ts b/gui/src/hooks/useInputHistory.ts index d936e5e9c..3d63886fe 100644 --- a/gui/src/hooks/useInputHistory.ts +++ b/gui/src/hooks/useInputHistory.ts @@ -1,5 +1,5 @@ import { JSONContent } from "@tiptap/react"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; import useUpdatingRef from "./useUpdatingRef"; @@ -10,112 +10,58 @@ const emptyJsonContent = () => ({ const MAX_HISTORY_LENGTH = 100; -// Completely isolated memory stores for different history types -// This ensures no crossover between edit and chat histories -const CHAT_HISTORY_STORE: JSONContent[] = []; -const EDIT_HISTORY_STORE: JSONContent[] = []; - -// Initialize the history stores from localStorage (only do this once) -let storesInitialized = false; -function initializeStores() { - - if (!storesInitialized) { - // Initialize chat history - const chatHistory = getLocalStorage('inputHistory_chat'); - if (chatHistory) { - CHAT_HISTORY_STORE.push(...chatHistory.slice(-MAX_HISTORY_LENGTH)); - } - - // Initialize edit history - const editHistory = getLocalStorage('inputHistory_edit'); - if (editHistory) { - EDIT_HISTORY_STORE.push(...editHistory.slice(-MAX_HISTORY_LENGTH)); - } - - storesInitialized = true; - } -} - - -// Initialize stores immediately -initializeStores(); - -/** - * Custom hook for managing input history with complete separation between history types - */ export function useInputHistory(historyKey: string) { - // Determine which history store to use - const historyStore = historyKey === 'edit' ? EDIT_HISTORY_STORE : CHAT_HISTORY_STORE; - const storageKey = historyKey === 'edit' ? 'inputHistory_edit' as const : 'inputHistory_chat' as const; - - // Use a reference to the appropriate history store - const [inputHistory, setInputHistory] = useState(historyStore); - const [pendingInput, setPendingInput] = useState(emptyJsonContent()); + const [inputHistory, setInputHistory] = useState( + getLocalStorage(`inputHistory_${historyKey}`)?.slice(-MAX_HISTORY_LENGTH) ?? + [], + ); + const [pendingInput, setPendingInput] = + useState(emptyJsonContent()); const [currentIndex, setCurrentIndex] = useState(inputHistory.length); - - // Keep the view of history updated when the underlying store changes - useEffect(() => { - setInputHistory([...historyStore]); - setCurrentIndex(historyStore.length); - }, [historyStore.length]); function prev(currentInput: JSONContent) { - if (currentIndex === inputHistory.length) { + let index = currentIndex; + + if (index === inputHistory.length) { setPendingInput(currentInput); } - if (currentIndex > 0) { - setCurrentIndex(currentIndex - 1); - return inputHistory[currentIndex - 1]; + if (index > 0 && index <= inputHistory.length) { + setCurrentIndex((prevState) => prevState - 1); + return inputHistory[index - 1]; } - - // Stay at the first history item if we're already there - if (currentIndex === 0 && inputHistory.length > 0) { - return inputHistory[0]; - } - - return currentInput; } function next() { - if (currentIndex < inputHistory.length) { - setCurrentIndex(currentIndex + 1); - - if (currentIndex === inputHistory.length - 1) { + let index = currentIndex; + if (index >= 0 && index < inputHistory.length) { + setCurrentIndex((prevState) => prevState + 1); + if (index === inputHistory.length - 1) { return pendingInput; } - - return inputHistory[currentIndex + 1]; + return inputHistory[index + 1]; } - - // Stay at pending input if we're already at the end - return pendingInput; } function add(inputValue: JSONContent) { setPendingInput(emptyJsonContent()); - // Don't add duplicates if ( - historyStore.length > 0 && - JSON.stringify(historyStore[historyStore.length - 1]) === JSON.stringify(inputValue) + JSON.stringify(inputHistory[inputHistory.length - 1]) === + JSON.stringify(inputValue) ) { - setCurrentIndex(historyStore.length); + setCurrentIndex(inputHistory.length); return; } - // Update the appropriate history store - while (historyStore.length >= MAX_HISTORY_LENGTH) { - historyStore.shift(); // Remove oldest items if we exceed the limit - } - historyStore.push(inputValue); - - // Update the view of history - setInputHistory([...historyStore]); - setCurrentIndex(historyStore.length); - - // Update localStorage - setLocalStorage(storageKey, [...historyStore]); + setCurrentIndex(inputHistory.length + 1); + setInputHistory((prev) => { + return [...prev, inputValue].slice(-MAX_HISTORY_LENGTH); + }); + setLocalStorage( + `inputHistory_${historyKey}`, + [...inputHistory, inputValue].slice(-MAX_HISTORY_LENGTH), + ); } const prevRef = useUpdatingRef(prev, [inputHistory]); From ed5befe4f9d8de8ba9f9a140581eb1fd49b415ef Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 19 Mar 2025 22:11:09 -0700 Subject: [PATCH 2/2] package-locks --- extensions/vscode/package-lock.json | 6 +++--- gui/package-lock.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index e196f39bb..e8f7b966b 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.12", + "version": "1.1.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.12", + "version": "1.1.13", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", @@ -109,7 +109,7 @@ "@continuedev/config-yaml": "^1.0.63", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", - "@continuedev/openai-adapters": "file:../packages/openai-adapters", + "@continuedev/openai-adapters": "^1.0.18", "@modelcontextprotocol/sdk": "^1.5.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1", diff --git a/gui/package-lock.json b/gui/package-lock.json index 0d780bd3c..ea7b94182 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -110,7 +110,7 @@ "@continuedev/config-yaml": "^1.0.63", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.2", - "@continuedev/openai-adapters": "file:../packages/openai-adapters", + "@continuedev/openai-adapters": "^1.0.18", "@modelcontextprotocol/sdk": "^1.5.0", "@mozilla/readability": "^0.5.0", "@octokit/rest": "^20.1.1",