Skip to content

Commit

Permalink
[bugfix] Clicking 'Code Now' will open multiple files (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo committed Mar 17, 2019
1 parent 2409d47 commit 0fb736c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/leetCodePreviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,37 @@ import { IProblem } from "./shared";
class LeetCodePreviewProvider implements Disposable {

private context: ExtensionContext;
private node: IProblem;
private panel: WebviewPanel | undefined;

public initialize(context: ExtensionContext): void {
this.context = context;
}

public async preview(node: IProblem): Promise<void> {
this.node = node;
if (!this.panel) {
this.panel = window.createWebviewPanel("leetcode.preview", "Preview Problem", ViewColumn.Active, {
enableScripts: true,
enableCommandUris: true,
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();
Expand Down

0 comments on commit 0fb736c

Please sign in to comment.