@@ -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}
0 commit comments