From 92b5c4ccf64a88c461bb32abc9ab02329651e6be Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 10 Jul 2024 12:53:40 -0500 Subject: [PATCH] fix: cmd+shft+l closes sidebar if focused (#1638) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: add docs and schema for "OS" provider (#1536) * ignore .env * ✨ use and cache imports for autocomplete (#1456) * ✨ use and cache imports for autocomplete * fix tsc * add voyage rerank-1 * import Handlebars * feat: open pane on install (#1564) * feat: open pane on activation * comment out testing code * chore: add telemetry for pageviews (#1576) * feat: update onboarding w/ embeddings model (#1570) * chore(gui): remove unused pages * feat: add embeddings step * feat: update styles * feat: copy button updates * fix: correct pull command for embed model * fix: remove commented code * fix: remove commented code * feat: simplify copy btn props * chore: rename onboarding selection event * feat: add provider config * fix: undo msg name * remove dead code * fix: invalid mode check * fix: remove testing logic * fix: fullscreen gui retains context when hidden, fixed fullscreen focusing (#1582) * small UI tweaks * media query * feat: add best experience onboarding * small fixes * feat: add free trial card to onboarding (#1600) * feat: add free trial card to onboarding * add import * chore: add telemetry for full screen toggle (#1618) * rerank-lite-1 * remove doccs * basic tests for VS Code extension * improved testing of VS Code extension * manually implement stop tokens for hf inference api * chore: onboarding metrics (#1626) * fix: pageview tracking * feat: add onboarding telemetry * create single `onboardingStatus` type * improved var naming * remove console logs * fix windows performance issue * rename vscodeExtension.ts * migration of onboarding variables * "stash" instead of "delete" in indexing progress * fix preview.yaml * also fix main.yaml * Update troubleshooting.md (#1637) * feat: close panel if main input is focused * add skip param * Update TipTapEditor.tsx * merge dev * Update commands.ts --------- Co-authored-by: Nate Sesti Co-authored-by: Nate Sesti <33237525+sestinj@users.noreply.github.com> Co-authored-by: Jonah Wagner --- core/indexing/LanceDbIndex.ts | 2 +- core/protocol/passThrough.ts | 1 + core/protocol/webview.ts | 1 + ...l.ts => ContinueGUIWebviewViewProvider.ts} | 5 +++ extensions/vscode/src/commands.ts | 42 ++++++++++++++----- .../vscode/src/extension/VsCodeExtension.ts | 2 +- gui/src/components/mainInput/TipTapEditor.tsx | 31 ++++---------- gui/src/hooks/useWebviewListener.ts | 34 ++++++++++----- 8 files changed, 73 insertions(+), 45 deletions(-) rename extensions/vscode/src/{debugPanel.ts => ContinueGUIWebviewViewProvider.ts} (98%) diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index 1f6ea709e..aa91f9fe5 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -65,7 +65,7 @@ export class LanceDbIndex implements CodebaseIndex { "lancedb_sqlite_artifact_id_column", async () => { await db.exec( - `ALTER TABLE lance_db_cache ADD COLUMN artifact_id TEXT NOT NULL DEFAULT 'UNDEFINED'`, + "ALTER TABLE lance_db_cache ADD COLUMN artifact_id TEXT NOT NULL DEFAULT 'UNDEFINED'", ); resolve(undefined); }, diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 131531108..a228194e3 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -54,5 +54,6 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = "indexProgress", "addContextItem", "refreshSubmenuItems", + "isContinueInputFocused", "didChangeAvailableProfiles", ]; diff --git a/core/protocol/webview.ts b/core/protocol/webview.ts index c0326bfa0..3cdf68c73 100644 --- a/core/protocol/webview.ts +++ b/core/protocol/webview.ts @@ -5,6 +5,7 @@ export type ToWebviewFromIdeOrCoreProtocol = { getDefaultModelTitle: [undefined, string]; indexProgress: [IndexingProgressUpdate, void]; refreshSubmenuItems: [undefined, void]; + isContinueInputFocused: [undefined, boolean]; addContextItem: [ { historyIndex: number; diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts similarity index 98% rename from extensions/vscode/src/debugPanel.ts rename to extensions/vscode/src/ContinueGUIWebviewViewProvider.ts index 7a125585e..c713244b0 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/ContinueGUIWebviewViewProvider.ts @@ -25,6 +25,11 @@ export class ContinueGUIWebviewViewProvider } private _webview?: vscode.Webview; + private _webviewView?: vscode.WebviewView; + + get isVisible() { + return this._webviewView?.visible; + } get webview() { return this._webview; diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index df9cde808..bac0580f0 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -19,7 +19,7 @@ import { quickPickStatusText, setupStatusBar, } from "./autocomplete/statusBar"; -import { ContinueGUIWebviewViewProvider } from "./debugPanel"; +import { ContinueGUIWebviewViewProvider } from "./ContinueGUIWebviewViewProvider"; import { DiffManager } from "./diff/horizontal"; import { VerticalPerLineDiffManager } from "./diff/verticalPerLine/manager"; import { QuickEdit } from "./quickEdit/QuickEdit"; @@ -82,7 +82,6 @@ function addCodeToContextFromRange( } async function addHighlightedCodeToContext( - edit: boolean, webviewProtocol: VsCodeWebviewProtocol | undefined, ) { const editor = vscode.window.activeTextEditor; @@ -322,19 +321,42 @@ const commandsMap: ( fullScreenPanel?.reveal(); } sidebar.webviewProtocol?.request("focusContinueInput", undefined); - await addHighlightedCodeToContext(false, sidebar.webviewProtocol); + await addHighlightedCodeToContext(sidebar.webviewProtocol); }, "continue.focusContinueInputWithoutClear": async () => { - if (!getFullScreenTab()) { - vscode.commands.executeCommand("continue.continueGUIView.focus"); - } - sidebar.webviewProtocol?.request( - "focusContinueInputWithoutClear", + const fullScreenTab = getFullScreenTab(); + + const isContinueInputFocused = await sidebar.webviewProtocol.request( + "isContinueInputFocused", undefined, ); - await addHighlightedCodeToContext(true, sidebar.webviewProtocol); + + if (isContinueInputFocused) { + // Handle closing the GUI only if we are focused on the input + if (fullScreenTab) { + fullScreenPanel?.dispose(); + } else { + vscode.commands.executeCommand("workbench.action.closeAuxiliaryBar"); + } + } else { + // Handle opening the GUI otherwise + if (!fullScreenTab) { + // focus sidebar + vscode.commands.executeCommand("continue.continueGUIView.focus"); + } else { + // focus fullscreen + fullScreenPanel?.reveal(); + } + + sidebar.webviewProtocol?.request( + "focusContinueInputWithoutClear", + undefined, + ); + + await addHighlightedCodeToContext(sidebar.webviewProtocol); + } }, - "continue.quickEdit": (injectedPrompt?: string) => { + "continue.quickEdit": async (injectedPrompt?: string) => { captureCommandTelemetry("quickEdit"); quickEdit.run(injectedPrompt); }, diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index 935d4492c..2a4c319ad 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -15,7 +15,7 @@ import { } from "../autocomplete/statusBar"; import { registerAllCommands } from "../commands"; import { registerDebugTracker } from "../debug/debug"; -import { ContinueGUIWebviewViewProvider } from "../debugPanel"; +import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider"; import { DiffManager } from "../diff/horizontal"; import { VerticalPerLineDiffManager } from "../diff/verticalPerLine/manager"; import { VsCodeIde } from "../ideProtocol"; diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 4b53fb00b..c0e941e45 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -151,8 +151,6 @@ function TipTapEditor(props: TipTapEditorProps) { ); const useActiveFile = useSelector(selectUseActiveFile); - const [inputFocused, setInputFocused] = useState(false); - const { saveSession } = useHistory(dispatch); const inSubmenuRef = useRef(undefined); @@ -655,16 +653,14 @@ function TipTapEditor(props: TipTapEditorProps) { ], ); - // On linux+jetbrains only was stealing focus - // useEffect(() => { - // if (props.isMainInput && editor && document.hasFocus()) { - // editor.commands.focus(); - // // setTimeout(() => { - // // // https://github.com/continuedev/continue/pull/881 - // // editor.commands.blur(); - // // }, 0); - // } - // }, [editor, props.isMainInput, historyLength, ignoreHighlightedCode]); + useWebviewListener( + "isContinueInputFocused", + async () => { + return props.isMainInput && editorFocusedRef.current; + }, + [editorFocusedRef, props.isMainInput], + !props.isMainInput, + ); const [showDragOverMsg, setShowDragOverMsg] = useState(false); @@ -748,22 +744,13 @@ function TipTapEditor(props: TipTapEditorProps) { { - setInputFocused(true); - }} - onBlur={() => { - // hack to stop from cancelling press of "Enter" - setTimeout(() => { - setInputFocused(false); - }, 100); - }} onClick={(event) => { event.stopPropagation(); }} />