Skip to content

Commit 8888ccb

Browse files
author
himanshu
committed
two webviews
1 parent 027d438 commit 8888ccb

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

extensions/vscode/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
}
128128
},
129129
"commands": [
130+
{
131+
"command": "pearai.switchWebview",
132+
"title": "PearAI: Switch Chat View"
133+
},
130134
{
131135
"command": "pearai.acceptDiff",
132136
"category": "PearAI",
@@ -530,6 +534,12 @@
530534
"id": "pearai.continueGUIView",
531535
"name": "",
532536
"visibility": "visible"
537+
},
538+
{
539+
"type": "webview",
540+
"id": "pearai.continueGUIView2",
541+
"name": "Chat 2",
542+
"visibility": "visible"
533543
}
534544
]
535545
},

extensions/vscode/src/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@ const commandsMap: (
526526
extensionContext.subscriptions,
527527
);
528528
},
529+
"pearai.switchWebview": () => {
530+
vscode.commands.executeCommand("pearai.internal.switchWebview");
531+
},
529532
"pearai.openConfigJson": () => {
530533
ide.openFile(getConfigJsonPath());
531534
},

extensions/vscode/src/extension/VsCodeExtension.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export class VsCodeExtension {
4141
private ide: VsCodeIde;
4242
private tabAutocompleteModel: TabAutocompleteModel;
4343
private sidebar: ContinueGUIWebviewViewProvider;
44-
private windowId: string;
44+
private sidebar2: ContinueGUIWebviewViewProvider;
45+
private activeWebview: 'sidebar' | 'sidebar2' = 'sidebar'; private windowId: string;
4546
private diffManager: DiffManager;
4647
private verticalDiffManager: VerticalPerLineDiffManager;
4748
webviewProtocolPromise: Promise<VsCodeWebviewProtocol>;
@@ -95,6 +96,29 @@ export class VsCodeExtension {
9596
);
9697
resolveWebviewProtocol(this.sidebar.webviewProtocol);
9798

99+
this.sidebar2 = new ContinueGUIWebviewViewProvider(
100+
configHandlerPromise,
101+
this.windowId + "_2",
102+
this.extensionContext,
103+
);
104+
105+
// Register second sidebar
106+
context.subscriptions.push(
107+
vscode.window.registerWebviewViewProvider(
108+
"pearai.continueGUIView2",
109+
this.sidebar2,
110+
{
111+
webviewOptions: { retainContextWhenHidden: true },
112+
},
113+
),
114+
);
115+
116+
context.subscriptions.push(
117+
vscode.commands.registerCommand("pearai.internal.switchWebview", () => {
118+
this.switchWebview();
119+
})
120+
);
121+
98122
// Config Handler with output channel
99123
const outputChannel = vscode.window.createOutputChannel(
100124
"PearAI",
@@ -372,6 +396,21 @@ export class VsCodeExtension {
372396

373397
static continueVirtualDocumentScheme = "pearai";
374398

399+
public switchWebview() {
400+
this.activeWebview = this.activeWebview === 'sidebar' ? 'sidebar2' : 'sidebar';
401+
const activeProvider = this.activeWebview === 'sidebar' ? this.sidebar : this.sidebar2;
402+
403+
this.webviewProtocolPromise.then(protocol => {
404+
if (activeProvider.webview) {
405+
protocol.webview = activeProvider.webview;
406+
}
407+
});
408+
// Refresh the webview content
409+
activeProvider.webviewProtocol?.request("didChangeAvailableProfiles", { profiles: [] });
410+
411+
vscode.commands.executeCommand(`pearai.continueGUIView${this.activeWebview === 'sidebar' ? '' : '2'}.focus`);
412+
}
413+
375414
// eslint-disable-next-line @typescript-eslint/naming-convention
376415
private PREVIOUS_BRANCH_FOR_WORKSPACE_DIR: { [dir: string]: string } = {};
377416

0 commit comments

Comments
 (0)