Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9f0999e

Browse files
committed
Make two event callbacks inheritable class method
1 parent 90c9480 commit 9f0999e

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

‎src/webview/LeetCodeWebview.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,8 @@ export abstract class LeetCodeWebview implements Disposable {
1111
private listener: Disposable;
1212

1313
public initialize(context: ExtensionContext): void {
14-
const { onDidChangeConfiguration } = this.getWebviewOption();
1514
this.context = context;
16-
if (onDidChangeConfiguration) {
17-
this.listener = workspace.onDidChangeConfiguration(onDidChangeConfiguration, this);
18-
} else {
19-
this.listener = workspace.onDidChangeConfiguration((event: ConfigurationChangeEvent) => {
20-
if (event.affectsConfiguration("markdown") && this.panel) {
21-
this.panel.webview.html = this.getWebviewContent();
22-
}
23-
}, this);
24-
}
15+
this.listener = workspace.onDidChangeConfiguration(this.onDidChangeConfiguration, this);
2516
}
2617

2718
public dispose(): void {
@@ -33,7 +24,7 @@ export abstract class LeetCodeWebview implements Disposable {
3324

3425
protected showWebviewInternal(): this is { panel: WebviewPanel } {
3526
if (!this.panel) {
36-
const { viewType, title, viewColumn, onDidReceiveMessage } = this.getWebviewOption();
27+
const { viewType, title, viewColumn } = this.getWebviewOption();
3728

3829
this.panel = window.createWebviewPanel(viewType, title, viewColumn || ViewColumn.One, {
3930
enableScripts: true,
@@ -47,15 +38,21 @@ export abstract class LeetCodeWebview implements Disposable {
4738
this.panel = undefined;
4839
}, null, this.context.subscriptions);
4940

50-
if (onDidReceiveMessage) {
51-
this.panel.webview.onDidReceiveMessage(onDidReceiveMessage, this, this.context.subscriptions);
52-
}
41+
this.panel.webview.onDidReceiveMessage(this.onDidReceiveMessage, this, this.context.subscriptions);
5342
}
5443

5544
this.panel.webview.html = this.getWebviewContent();
5645
return true;
5746
}
5847

48+
protected async onDidChangeConfiguration(event: ConfigurationChangeEvent): Promise<void> {
49+
if (this.panel && event.affectsConfiguration("markdown")) {
50+
this.panel.webview.html = this.getWebviewContent();
51+
}
52+
}
53+
54+
protected async onDidReceiveMessage(/* message */_: any): Promise<void> { /* no special rule */ }
55+
5956
protected abstract getWebviewOption(): ILeetCodeWebviewOption;
6057

6158
protected abstract getWebviewContent(): string;
@@ -65,6 +62,4 @@ export interface ILeetCodeWebviewOption {
6562
viewType: string;
6663
title: string;
6764
viewColumn?: ViewColumn;
68-
onDidReceiveMessage?: (message: any) => Promise<void>;
69-
onDidChangeConfiguration?: (event: ConfigurationChangeEvent) => Promise<void>;
7065
}

‎src/webview/leetCodePreviewProvider.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,27 @@ class LeetCodePreviewProvider extends LeetCodeWebview {
1313
private description: IDescription;
1414

1515
public async show(node: IProblem): Promise<void> {
16-
constdescString: string=await leetCodeExecutor.getDescription(node);
16+
this.description=this.parseDescription(await leetCodeExecutor.getDescription(node),node);
1717
this.node = node;
18-
this.description = this.parseDescription(descString, node);
1918
if (this.showWebviewInternal()) {
20-
this.panel.webview.html = this.getWebviewContent();
2119
this.panel.title = `${node.name}: Preview`;
2220
this.panel.reveal(ViewColumn.One);
2321
}
2422
}
2523

24+
protected async onDidReceiveMessage(message: IWebViewMessage): Promise<void> {
25+
switch (message.command) {
26+
case "ShowProblem": {
27+
await commands.executeCommand("leetcode.showProblem", this.node);
28+
break;
29+
}
30+
}
31+
}
32+
2633
protected getWebviewOption(): ILeetCodeWebviewOption {
2734
return {
2835
viewType: "leetcode.preview",
2936
title: "Preview Problem",
30-
onDidReceiveMessage: async (message: IWebViewMessage): Promise<void> => {
31-
switch (message.command) {
32-
case "ShowProblem": {
33-
await commands.executeCommand("leetcode.showProblem", this.node);
34-
break;
35-
}
36-
}
37-
},
3837
};
3938
}
4039

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /