Skip to content

Commit 0fb736c

Browse files
authored
[bugfix] Clicking 'Code Now' will open multiple files (LeetCode-OpenSource#216)
1 parent 2409d47 commit 0fb736c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/leetCodePreviewProvider.ts

+15-12
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,37 @@ import { IProblem } from "./shared";
44
class LeetCodePreviewProvider implements Disposable {
55

66
private context: ExtensionContext;
7+
private node: IProblem;
78
private panel: WebviewPanel | undefined;
89

910
public initialize(context: ExtensionContext): void {
1011
this.context = context;
1112
}
1213

1314
public async preview(node: IProblem): Promise<void> {
15+
this.node = node;
1416
if (!this.panel) {
1517
this.panel = window.createWebviewPanel("leetcode.preview", "Preview Problem", ViewColumn.Active, {
1618
enableScripts: true,
1719
enableCommandUris: true,
1820
enableFindWidget: true,
1921
retainContextWhenHidden: true,
2022
});
21-
}
2223

23-
this.panel.onDidDispose(() => {
24-
this.panel = undefined;
25-
}, null, this.context.subscriptions);
24+
this.panel.webview.onDidReceiveMessage(async (message: IWebViewMessage) => {
25+
switch (message.command) {
26+
case "ShowProblem":
27+
await commands.executeCommand("leetcode.showProblem", this.node);
28+
this.dispose();
29+
return;
30+
}
31+
}, this, this.context.subscriptions);
32+
33+
this.panel.onDidDispose(() => {
34+
this.panel = undefined;
35+
}, null, this.context.subscriptions);
36+
}
2637

27-
this.panel.webview.onDidReceiveMessage(async (message: IWebViewMessage) => {
28-
switch (message.command) {
29-
case "ShowProblem":
30-
await commands.executeCommand("leetcode.showProblem", node);
31-
this.dispose();
32-
return;
33-
}
34-
});
3538
this.panel.webview.html = await this.provideHtmlContent(node);
3639
this.panel.title = node.name;
3740
this.panel.reveal();

0 commit comments

Comments
 (0)