@@ -28,7 +28,10 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
2828
2929declare const ResizeObserver : any ;
3030
31- const webviewStateKey = 'webviewState' ;
31+ const storageKeys = {
32+ webviewState : 'webviewState' ,
33+ title : 'title'
34+ } as const ;
3235
3336export class WebviewViewPane extends ViewPane {
3437
@@ -38,6 +41,9 @@ export class WebviewViewPane extends ViewPane {
3841 private _container ?: HTMLElement ;
3942 private _resizeObserver ?: any ;
4043
44+ private readonly defaultTitle : string ;
45+ private setTitle : string | undefined ;
46+
4147 private readonly memento : Memento ;
4248 private readonly viewState : MementoObject ;
4349
@@ -60,10 +66,16 @@ export class WebviewViewPane extends ViewPane {
6066 @IViewsService private readonly viewService : IViewsService ,
6167 ) {
6268 super ( { ...options , titleMenuId : MenuId . ViewTitle } , keybindingService , contextMenuService , configurationService , contextKeyService , viewDescriptorService , instantiationService , openerService , themeService , telemetryService ) ;
69+ this . defaultTitle = this . title ;
6370
6471 this . memento = new Memento ( `webviewView.${ this . id } ` , storageService ) ;
6572 this . viewState = this . memento . getMemento ( StorageScope . WORKSPACE ) ;
6673
74+ const storedTitle = this . viewState [ storageKeys . title ] ;
75+ if ( typeof storedTitle === 'string' ) {
76+ this . updateTitle ( storedTitle ) ;
77+ }
78+
6779 this . _register ( this . onDidChangeBodyVisibility ( ( ) => this . updateTreeVisibility ( ) ) ) ;
6880 this . updateTreeVisibility ( ) ;
6981 }
@@ -108,8 +120,9 @@ export class WebviewViewPane extends ViewPane {
108120
109121 public saveState ( ) {
110122 if ( this . _webview ) {
111- this . viewState [ webviewStateKey ] = this . _webview . state ;
123+ this . viewState [ storageKeys . webviewState ] = this . _webview . state ;
112124 }
125+ this . viewState [ storageKeys . title ] = this . setTitle ;
113126
114127 this . memento . saveMemento ( ) ;
115128 super . saveState ( ) ;
@@ -142,15 +155,15 @@ export class WebviewViewPane extends ViewPane {
142155
143156 const webviewId = `webviewView-${ this . id . replace ( / [ ^ a - z 0 - 9 ] / gi, '-' ) } ` . toLowerCase ( ) ;
144157 const webview = this . webviewService . createWebviewOverlay ( webviewId , { } , { } , undefined ) ;
145- webview . state = this . viewState [ ' webviewState' ] ;
158+ webview . state = this . viewState [ storageKeys . webviewState ] ;
146159 this . _webview = webview ;
147160
148161 this . _register ( toDisposable ( ( ) => {
149162 this . _webview ?. release ( this ) ;
150163 } ) ) ;
151164
152165 this . _register ( webview . onDidUpdateState ( ( ) => {
153- this . viewState [ webviewStateKey ] = webview . state ;
166+ this . viewState [ storageKeys . webviewState ] = webview . state ;
154167 } ) ) ;
155168
156169 const source = this . _register ( new CancellationTokenSource ( ) ) ;
@@ -164,8 +177,8 @@ export class WebviewViewPane extends ViewPane {
164177 onDidChangeVisibility : this . onDidChangeBodyVisibility ,
165178 onDispose : this . onDispose ,
166179
167- get title ( ) { return self . title ; } ,
168- set title ( value : string ) { self . updateTitle ( value ) ; } ,
180+ get title ( ) : string | undefined { return self . setTitle ; } ,
181+ set title ( value : string | undefined ) { self . updateTitle ( value ) ; } ,
169182
170183 get description ( ) : string | undefined { return self . titleDescription ; } ,
171184 set description ( value : string | undefined ) { self . updateTitleDescription ( value ) ; } ,
@@ -180,6 +193,11 @@ export class WebviewViewPane extends ViewPane {
180193 }
181194 }
182195
196+ protected updateTitle ( value : string | undefined ) {
197+ this . setTitle = value ;
198+ super . updateTitle ( typeof value === 'string' ? value : this . defaultTitle ) ;
199+ }
200+
183201 private async withProgress ( task : ( ) => Promise < void > ) : Promise < void > {
184202 return this . progressService . withProgress ( { location : this . id , delay : 500 } , task ) ;
185203 }
0 commit comments