From c1ae7bba3a5118be5d551f6cad94dcc8789eddf4 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Sun, 6 Oct 2024 12:45:46 +0200 Subject: [PATCH] Add a help center shortcut --- core/protocol/ideWebview.ts | 5 ++++ extensions/vscode/package.json | 6 +++++ extensions/vscode/src/commands.ts | 34 +++++++++++++++++-------- gui/src/components/Layout.tsx | 12 +++++++++ gui/src/hooks/useNavigationListener.tsx | 14 ---------- 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 774da7ee5..523ba4995 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -58,8 +58,13 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & { }, void, ]; + navigateTo: [{ path: string; toggle?: boolean }, void]; addModel: [undefined, void]; + openSettings: [undefined, void]; + /** + * @deprecated Use navigateTo with a path instead. + */ viewHistory: [undefined, void]; newSession: [undefined, void]; setTheme: [{ theme: any }, void]; diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 193546288..5a4dfb658 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -221,6 +221,12 @@ "icon": "$(history)", "group": "Continue" }, + { + "command": "continue.navigateTo", + "category": "Continue", + "title": "Navigate to a path", + "group": "Continue" + }, { "command": "continue.writeCommentsForCode", "category": "Continue", diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 0edf63227..b49e9a184 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -165,6 +165,17 @@ async function addEntireFileToContext( }); } +function focusGUI() { + const fullScreenTab = getFullScreenTab(); + if (!fullScreenTab) { + // focus sidebar + vscode.commands.executeCommand("continue.continueGUIView.focus"); + } else { + // focus fullscreen + fullScreenPanel?.reveal(); + } +} + // Copy everything over from extension.ts const commandsMap: ( ide: IDE, @@ -315,14 +326,7 @@ const commandsMap: ( core.invoke("context/indexDocs", { reIndex: true }); }, "continue.focusContinueInput": async () => { - const fullScreenTab = getFullScreenTab(); - if (!fullScreenTab) { - // focus sidebar - vscode.commands.executeCommand("continue.continueGUIView.focus"); - } else { - // focus fullscreen - fullScreenPanel?.reveal(); - } + focusGUI(); sidebar.webviewProtocol?.request("focusContinueInput", undefined); await addHighlightedCodeToContext(sidebar.webviewProtocol); }, @@ -631,8 +635,8 @@ const commandsMap: ( currentStatus === StatusBarStatus.Paused ? StatusBarStatus.Enabled : currentStatus === StatusBarStatus.Disabled - ? StatusBarStatus.Paused - : StatusBarStatus.Disabled; + ? StatusBarStatus.Paused + : StatusBarStatus.Disabled; } else { // Toggle between Disabled and Enabled targetStatus = @@ -641,6 +645,9 @@ const commandsMap: ( : StatusBarStatus.Disabled; } quickPick.items = [ + { + label: "$(question) Open help center", + }, { label: "$(comment) Open chat (Cmd+L)", }, @@ -698,6 +705,9 @@ const commandsMap: ( "$(screen-full) Open full screen chat (Cmd+K Cmd+M)" ) { vscode.commands.executeCommand("continue.toggleFullScreen"); + } else if (selectedOption === "$(question) Open help center") { + focusGUI(); + vscode.commands.executeCommand("continue.navigateTo", "/more"); } quickPick.dispose(); }); @@ -717,6 +727,10 @@ const commandsMap: ( client.sendFeedback(feedback, lastLines); } }, + "continue.navigateTo": (path: string) => { + sidebar.webviewProtocol?.request("navigateTo", { path }); + focusGUI(); + }, }; }; diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index f0213197b..259de2e25 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -115,6 +115,18 @@ const Layout = () => { [location, navigate], ); + useWebviewListener( + "navigateTo", + async (data) => { + if (data.toggle && location.pathname === data.path) { + navigate("/"); + } else { + navigate(data.path); + } + }, + [location, navigate], + ); + useWebviewListener( "incrementFtc", async () => { diff --git a/gui/src/hooks/useNavigationListener.tsx b/gui/src/hooks/useNavigationListener.tsx index 0a08ccc5c..cadc40330 100644 --- a/gui/src/hooks/useNavigationListener.tsx +++ b/gui/src/hooks/useNavigationListener.tsx @@ -13,7 +13,6 @@ const openGUITypes: (keyof ToWebviewProtocol)[] = [ export const useNavigationListener = () => { const navigate = useNavigate(); - const location = useLocation(); for (const messageType of openGUITypes) { useWebviewListener( @@ -34,17 +33,4 @@ export const useNavigationListener = () => { [navigate], ); } - - useWebviewListener( - "viewHistory", - async () => { - // Toggle the history page / main page - if (location.pathname === "/history") { - navigate("/"); - } else { - navigate("/history"); - } - }, - [location, navigate], - ); };