From 0fb736c037e59c3c91a84b5fde6a87a6b815e3fe Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Sun, 17 Mar 2019 21:07:19 +0800 Subject: [PATCH] [bugfix] Clicking 'Code Now' will open multiple files (#216) --- src/leetCodePreviewProvider.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/leetCodePreviewProvider.ts b/src/leetCodePreviewProvider.ts index 0b1b30dc..e2e3d0aa 100644 --- a/src/leetCodePreviewProvider.ts +++ b/src/leetCodePreviewProvider.ts @@ -4,6 +4,7 @@ import { IProblem } from "./shared"; class LeetCodePreviewProvider implements Disposable { private context: ExtensionContext; + private node: IProblem; private panel: WebviewPanel | undefined; public initialize(context: ExtensionContext): void { @@ -11,6 +12,7 @@ class LeetCodePreviewProvider implements Disposable { } public async preview(node: IProblem): Promise { + this.node = node; if (!this.panel) { this.panel = window.createWebviewPanel("leetcode.preview", "Preview Problem", ViewColumn.Active, { enableScripts: true, @@ -18,20 +20,21 @@ class LeetCodePreviewProvider implements Disposable { enableFindWidget: true, retainContextWhenHidden: true, }); - } - this.panel.onDidDispose(() => { - this.panel = undefined; - }, null, this.context.subscriptions); + this.panel.webview.onDidReceiveMessage(async (message: IWebViewMessage) => { + switch (message.command) { + case "ShowProblem": + await commands.executeCommand("leetcode.showProblem", this.node); + this.dispose(); + return; + } + }, this, this.context.subscriptions); + + this.panel.onDidDispose(() => { + this.panel = undefined; + }, null, this.context.subscriptions); + } - this.panel.webview.onDidReceiveMessage(async (message: IWebViewMessage) => { - switch (message.command) { - case "ShowProblem": - await commands.executeCommand("leetcode.showProblem", node); - this.dispose(); - return; - } - }); this.panel.webview.html = await this.provideHtmlContent(node); this.panel.title = node.name; this.panel.reveal();