Skip to content

Commit f19143e

Browse files
authored
Fix bug where menu would open in sidebar and open tab (RooCodeInc#2618)
* Fix bug where menu would open in sidebar and open tab * Create nasty-spies-check.md
1 parent ed16aff commit f19143e

File tree

3 files changed

+73
-25
lines changed

3 files changed

+73
-25
lines changed

.changeset/nasty-spies-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Fix bug where menu would open in sidebar and open tab

src/core/webview/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ export class WebviewProvider implements vscode.WebviewViewProvider {
4848
return Array.from(this.activeInstances)
4949
}
5050

51+
public static getSidebarInstance() {
52+
return Array.from(this.activeInstances).find((instance) => instance.view && "onDidChangeVisibility" in instance.view)
53+
}
54+
55+
public static getTabInstances(): WebviewProvider[] {
56+
return Array.from(this.activeInstances).filter((instance) => instance.view && "onDidChangeViewState" in instance.view)
57+
}
58+
5159
async resolveWebviewView(webviewView: vscode.WebviewView | vscode.WebviewPanel) {
5260
this.view = webviewView
5361

src/extension.ts

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,37 @@ export function activate(context: vscode.ExtensionContext) {
4141
)
4242

4343
context.subscriptions.push(
44-
vscode.commands.registerCommand("cline.plusButtonClicked", async () => {
45-
WebviewProvider.getAllInstances().forEach(async (instance) => {
46-
await instance.controller.clearTask()
47-
await instance.controller.postStateToWebview()
48-
await instance.controller.postMessageToWebview({
44+
vscode.commands.registerCommand("cline.plusButtonClicked", async (webview: any) => {
45+
const openChat = async (instance?: WebviewProvider) => {
46+
await instance?.controller.clearTask()
47+
await instance?.controller.postStateToWebview()
48+
await instance?.controller.postMessageToWebview({
4949
type: "action",
5050
action: "chatButtonClicked",
5151
})
52-
})
52+
}
53+
const isSidebar = !webview
54+
if (isSidebar) {
55+
openChat(WebviewProvider.getSidebarInstance())
56+
} else {
57+
WebviewProvider.getTabInstances().forEach(openChat)
58+
}
5359
}),
5460
)
5561

5662
context.subscriptions.push(
57-
vscode.commands.registerCommand("cline.mcpButtonClicked", () => {
58-
WebviewProvider.getAllInstances().forEach((instance) => {
59-
instance.controller.postMessageToWebview({
63+
vscode.commands.registerCommand("cline.mcpButtonClicked", (webview: any) => {
64+
const openMcp = (instance?: WebviewProvider) =>
65+
instance?.controller.postMessageToWebview({
6066
type: "action",
6167
action: "mcpButtonClicked",
6268
})
63-
})
69+
const isSidebar = !webview
70+
if (isSidebar) {
71+
openMcp(WebviewProvider.getSidebarInstance())
72+
} else {
73+
WebviewProvider.getTabInstances().forEach(openMcp)
74+
}
6475
}),
6576
)
6677

@@ -101,34 +112,58 @@ export function activate(context: vscode.ExtensionContext) {
101112
context.subscriptions.push(vscode.commands.registerCommand("cline.openInNewTab", openClineInNewTab))
102113

103114
context.subscriptions.push(
104-
vscode.commands.registerCommand("cline.settingsButtonClicked", () => {
115+
vscode.commands.registerCommand("cline.settingsButtonClicked", (webview: any) => {
105116
WebviewProvider.getAllInstances().forEach((instance) => {
106-
instance.controller.postMessageToWebview({
107-
type: "action",
108-
action: "settingsButtonClicked",
109-
})
117+
const openSettings = async (instance?: WebviewProvider) => {
118+
instance?.controller.postMessageToWebview({
119+
type: "action",
120+
action: "settingsButtonClicked",
121+
})
122+
}
123+
const isSidebar = !webview
124+
if (isSidebar) {
125+
openSettings(WebviewProvider.getSidebarInstance())
126+
} else {
127+
WebviewProvider.getTabInstances().forEach(openSettings)
128+
}
110129
})
111130
}),
112131
)
113132

114133
context.subscriptions.push(
115-
vscode.commands.registerCommand("cline.historyButtonClicked", () => {
134+
vscode.commands.registerCommand("cline.historyButtonClicked", (webview: any) => {
116135
WebviewProvider.getAllInstances().forEach((instance) => {
117-
instance.controller.postMessageToWebview({
118-
type: "action",
119-
action: "historyButtonClicked",
120-
})
136+
const openHistory = async (instance?: WebviewProvider) => {
137+
instance?.controller.postMessageToWebview({
138+
type: "action",
139+
action: "historyButtonClicked",
140+
})
141+
}
142+
const isSidebar = !webview
143+
if (isSidebar) {
144+
openHistory(WebviewProvider.getSidebarInstance())
145+
} else {
146+
WebviewProvider.getTabInstances().forEach(openHistory)
147+
}
121148
})
122149
}),
123150
)
124151

125152
context.subscriptions.push(
126-
vscode.commands.registerCommand("cline.accountButtonClicked", () => {
153+
vscode.commands.registerCommand("cline.accountButtonClicked", (webview: any) => {
127154
WebviewProvider.getAllInstances().forEach((instance) => {
128-
instance.controller.postMessageToWebview({
129-
type: "action",
130-
action: "accountButtonClicked",
131-
})
155+
const openAccount = async (instance?: WebviewProvider) => {
156+
instance?.controller.postMessageToWebview({
157+
type: "action",
158+
action: "accountButtonClicked",
159+
})
160+
}
161+
const isSidebar = !webview
162+
if (isSidebar) {
163+
openAccount(WebviewProvider.getSidebarInstance())
164+
} else {
165+
WebviewProvider.getTabInstances().forEach(openAccount)
166+
}
132167
})
133168
}),
134169
)

0 commit comments

Comments
 (0)