From f19143e35c1d286b8a77b732879d7d31aebef050 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Tue, 1 Apr 2025 16:05:01 -0700 Subject: [PATCH] Fix bug where menu would open in sidebar and open tab (#2618) * Fix bug where menu would open in sidebar and open tab * Create nasty-spies-check.md --- .changeset/nasty-spies-check.md | 5 ++ src/core/webview/index.ts | 8 ++++ src/extension.ts | 85 +++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 .changeset/nasty-spies-check.md diff --git a/.changeset/nasty-spies-check.md b/.changeset/nasty-spies-check.md new file mode 100644 index 0000000000..773158fc95 --- /dev/null +++ b/.changeset/nasty-spies-check.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Fix bug where menu would open in sidebar and open tab diff --git a/src/core/webview/index.ts b/src/core/webview/index.ts index 6ad3e62b99..17b4352a2c 100644 --- a/src/core/webview/index.ts +++ b/src/core/webview/index.ts @@ -48,6 +48,14 @@ export class WebviewProvider implements vscode.WebviewViewProvider { return Array.from(this.activeInstances) } + public static getSidebarInstance() { + return Array.from(this.activeInstances).find((instance) => instance.view && "onDidChangeVisibility" in instance.view) + } + + public static getTabInstances(): WebviewProvider[] { + return Array.from(this.activeInstances).filter((instance) => instance.view && "onDidChangeViewState" in instance.view) + } + async resolveWebviewView(webviewView: vscode.WebviewView | vscode.WebviewPanel) { this.view = webviewView diff --git a/src/extension.ts b/src/extension.ts index 2123ce3242..ed22d984d5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -41,26 +41,37 @@ export function activate(context: vscode.ExtensionContext) { ) context.subscriptions.push( - vscode.commands.registerCommand("cline.plusButtonClicked", async () => { - WebviewProvider.getAllInstances().forEach(async (instance) => { - await instance.controller.clearTask() - await instance.controller.postStateToWebview() - await instance.controller.postMessageToWebview({ + vscode.commands.registerCommand("cline.plusButtonClicked", async (webview: any) => { + const openChat = async (instance?: WebviewProvider) => { + await instance?.controller.clearTask() + await instance?.controller.postStateToWebview() + await instance?.controller.postMessageToWebview({ type: "action", action: "chatButtonClicked", }) - }) + } + const isSidebar = !webview + if (isSidebar) { + openChat(WebviewProvider.getSidebarInstance()) + } else { + WebviewProvider.getTabInstances().forEach(openChat) + } }), ) context.subscriptions.push( - vscode.commands.registerCommand("cline.mcpButtonClicked", () => { - WebviewProvider.getAllInstances().forEach((instance) => { - instance.controller.postMessageToWebview({ + vscode.commands.registerCommand("cline.mcpButtonClicked", (webview: any) => { + const openMcp = (instance?: WebviewProvider) => + instance?.controller.postMessageToWebview({ type: "action", action: "mcpButtonClicked", }) - }) + const isSidebar = !webview + if (isSidebar) { + openMcp(WebviewProvider.getSidebarInstance()) + } else { + WebviewProvider.getTabInstances().forEach(openMcp) + } }), ) @@ -101,34 +112,58 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.commands.registerCommand("cline.openInNewTab", openClineInNewTab)) context.subscriptions.push( - vscode.commands.registerCommand("cline.settingsButtonClicked", () => { + vscode.commands.registerCommand("cline.settingsButtonClicked", (webview: any) => { WebviewProvider.getAllInstances().forEach((instance) => { - instance.controller.postMessageToWebview({ - type: "action", - action: "settingsButtonClicked", - }) + const openSettings = async (instance?: WebviewProvider) => { + instance?.controller.postMessageToWebview({ + type: "action", + action: "settingsButtonClicked", + }) + } + const isSidebar = !webview + if (isSidebar) { + openSettings(WebviewProvider.getSidebarInstance()) + } else { + WebviewProvider.getTabInstances().forEach(openSettings) + } }) }), ) context.subscriptions.push( - vscode.commands.registerCommand("cline.historyButtonClicked", () => { + vscode.commands.registerCommand("cline.historyButtonClicked", (webview: any) => { WebviewProvider.getAllInstances().forEach((instance) => { - instance.controller.postMessageToWebview({ - type: "action", - action: "historyButtonClicked", - }) + const openHistory = async (instance?: WebviewProvider) => { + instance?.controller.postMessageToWebview({ + type: "action", + action: "historyButtonClicked", + }) + } + const isSidebar = !webview + if (isSidebar) { + openHistory(WebviewProvider.getSidebarInstance()) + } else { + WebviewProvider.getTabInstances().forEach(openHistory) + } }) }), ) context.subscriptions.push( - vscode.commands.registerCommand("cline.accountButtonClicked", () => { + vscode.commands.registerCommand("cline.accountButtonClicked", (webview: any) => { WebviewProvider.getAllInstances().forEach((instance) => { - instance.controller.postMessageToWebview({ - type: "action", - action: "accountButtonClicked", - }) + const openAccount = async (instance?: WebviewProvider) => { + instance?.controller.postMessageToWebview({ + type: "action", + action: "accountButtonClicked", + }) + } + const isSidebar = !webview + if (isSidebar) { + openAccount(WebviewProvider.getSidebarInstance()) + } else { + WebviewProvider.getTabInstances().forEach(openAccount) + } }) }), )