From e2458b283f71d17b2a773bf60c1b43fab9a66bf2 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Tue, 1 Apr 2025 10:38:52 -0700 Subject: [PATCH] Fix bug where menu buttons wouldn't open view in sidebar (#2607) --- src/core/webview/index.ts | 4 +++ src/extension.ts | 76 ++++++++++++++------------------------- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/src/core/webview/index.ts b/src/core/webview/index.ts index 5f115fffff..6ad3e62b99 100644 --- a/src/core/webview/index.ts +++ b/src/core/webview/index.ts @@ -44,6 +44,10 @@ export class WebviewProvider implements vscode.WebviewViewProvider { return findLast(Array.from(this.activeInstances), (instance) => instance.view?.visible === true) } + public static getAllInstances(): WebviewProvider[] { + return Array.from(this.activeInstances) + } + async resolveWebviewView(webviewView: vscode.WebviewView | vscode.WebviewPanel) { this.view = webviewView diff --git a/src/extension.ts b/src/extension.ts index 42300ca30a..2123ce3242 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -42,33 +42,24 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand("cline.plusButtonClicked", async () => { - Logger.log("Plus button Clicked") - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - await visibleWebview.controller.clearTask() - await visibleWebview.controller.postStateToWebview() - await visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "chatButtonClicked", + WebviewProvider.getAllInstances().forEach(async (instance) => { + await instance.controller.clearTask() + await instance.controller.postStateToWebview() + await instance.controller.postMessageToWebview({ + type: "action", + action: "chatButtonClicked", + }) }) }), ) context.subscriptions.push( vscode.commands.registerCommand("cline.mcpButtonClicked", () => { - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "mcpButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "mcpButtonClicked", + }) }) }), ) @@ -111,46 +102,33 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand("cline.settingsButtonClicked", () => { - //vscode.window.showInformationMessage(message) - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "settingsButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "settingsButtonClicked", + }) }) }), ) context.subscriptions.push( vscode.commands.registerCommand("cline.historyButtonClicked", () => { - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "historyButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "historyButtonClicked", + }) }) }), ) context.subscriptions.push( vscode.commands.registerCommand("cline.accountButtonClicked", () => { - const visibleWebview = WebviewProvider.getVisibleInstance() - if (!visibleWebview) { - Logger.log("Cannot find any visible Cline instances.") - return - } - - visibleWebview.controller.postMessageToWebview({ - type: "action", - action: "accountButtonClicked", + WebviewProvider.getAllInstances().forEach((instance) => { + instance.controller.postMessageToWebview({ + type: "action", + action: "accountButtonClicked", + }) }) }), )