@@ -23,7 +23,7 @@ export class WebviewEditor extends BaseEditor {
2323
2424 public static readonly ID = 'WebviewEditor' ;
2525
26- private _webview : WebviewEditorOverlay | undefined ;
26+ private readonly _scopedContextKeyService = this . _register ( new MutableDisposable < IContextKeyService > ( ) ) ;
2727 private _findWidgetVisible : IContextKey < boolean > ;
2828
2929 private _editorFrame ?: HTMLElement ;
@@ -38,15 +38,14 @@ export class WebviewEditor extends BaseEditor {
3838 constructor (
3939 @ITelemetryService telemetryService : ITelemetryService ,
4040 @IThemeService themeService : IThemeService ,
41- @IContextKeyService private _contextKeyService : IContextKeyService ,
41+ @IContextKeyService private readonly _contextKeyService : IContextKeyService ,
4242 @IEditorService private readonly _editorService : IEditorService ,
4343 @IWindowService private readonly _windowService : IWindowService ,
4444 @IStorageService storageService : IStorageService
4545 ) {
4646 super ( WebviewEditor . ID , telemetryService , themeService , storageService ) ;
47- if ( _contextKeyService ) {
48- this . _findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE . bindTo ( _contextKeyService ) ;
49- }
47+
48+ this . _findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE . bindTo ( _contextKeyService ) ;
5049 }
5150
5251 public get isWebviewEditor ( ) {
@@ -85,16 +84,15 @@ export class WebviewEditor extends BaseEditor {
8584 }
8685
8786 public layout ( _dimension : DOM . Dimension ) : void {
88- if ( this . _webview ) {
89- this . doUpdateContainer ( this . _webview ) ;
90- this . _webview . layout ( ) ;
87+ if ( this . input && this . input instanceof WebviewEditorInput ) {
88+ this . synchronizeWebviewContainerDimensions ( this . input . webview ) ;
89+ this . input . webview . layout ( ) ;
9190 }
9291 }
9392
9493 public focus ( ) : void {
9594 super . focus ( ) ;
9695 if ( ! this . _onFocusWindowHandler . value ) {
97-
9896 // Make sure we restore focus when switching back to a VS Code window
9997 this . _onFocusWindowHandler . value = this . _windowService . onDidChangeFocus ( focused => {
10098 if ( focused && this . _editorService . activeControl === this ) {
@@ -106,13 +104,13 @@ export class WebviewEditor extends BaseEditor {
106104 }
107105
108106 public withWebview ( f : ( element : Webview ) => void ) : void {
109- if ( this . _webview ) {
110- f ( this . _webview ) ;
107+ if ( this . input && this . input instanceof WebviewEditorInput ) {
108+ f ( this . input . webview ) ;
111109 }
112110 }
113111
114112 protected setEditorVisible ( visible : boolean , group : IEditorGroup ) : void {
115- const webview = ( this . input && ( this . input as WebviewEditorInput ) . webview ) || this . _webview ;
113+ const webview = this . input && ( this . input as WebviewEditorInput ) . webview ;
116114 if ( webview ) {
117115 if ( visible ) {
118116 webview . claim ( this ) ;
@@ -130,14 +128,12 @@ export class WebviewEditor extends BaseEditor {
130128 this . input . webview . release ( this ) ;
131129 }
132130
133- this . _webview = undefined ;
134131 super . clearInput ( ) ;
135132 }
136133
137134 public async setInput ( input : WebviewEditorInput , options : EditorOptions , token : CancellationToken ) : Promise < void > {
138- if ( this . input && ( this . input as WebviewEditorInput ) . webview ) {
139- ( this . input as WebviewEditorInput ) . webview ! . release ( this ) ;
140- this . _webview = undefined ;
135+ if ( this . input && this . input instanceof WebviewEditorInput ) {
136+ this . input . webview . release ( this ) ;
141137 }
142138
143139 await super . setInput ( input , options , token ) ;
@@ -149,32 +145,27 @@ export class WebviewEditor extends BaseEditor {
149145 if ( this . group ) {
150146 input . updateGroup ( this . group . id ) ;
151147 }
148+
152149 this . claimWebview ( input ) ;
153150 }
154151
155152 private claimWebview ( input : WebviewEditorInput ) : void {
156- if ( this . _webview ) {
157- this . _webview . claim ( this ) ;
158- return ;
159- }
160-
161- this . _webview = input . webview ;
162- this . _webview . claim ( this ) ;
153+ input . webview . claim ( this ) ;
163154
164- if ( this . _webview . options . enableFindWidget ) {
165- this . _contextKeyService = this . _register ( this . _contextKeyService . createScoped ( this . _webview . container ) ) ;
166- this . _findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE . bindTo ( this . _contextKeyService ) ;
155+ if ( input . webview . options . enableFindWidget ) {
156+ this . _scopedContextKeyService . value = this . _contextKeyService . createScoped ( input . webview . container ) ;
157+ this . _findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE . bindTo ( this . _scopedContextKeyService . value ) ;
167158 }
168159
169160 if ( this . _content ) {
170- this . _content . setAttribute ( 'aria-flowto' , this . _webview . container . id ) ;
161+ this . _content . setAttribute ( 'aria-flowto' , input . webview . container . id ) ;
171162 }
172163
173- this . doUpdateContainer ( this . _webview ) ;
174- this . trackFocus ( this . _webview ) ;
164+ this . synchronizeWebviewContainerDimensions ( input . webview ) ;
165+ this . trackFocus ( input . webview ) ;
175166 }
176167
177- private doUpdateContainer ( webview : WebviewEditorOverlay ) {
168+ private synchronizeWebviewContainerDimensions ( webview : WebviewEditorOverlay ) {
178169 const webviewContainer = webview . container ;
179170 if ( webviewContainer && webviewContainer . parentElement && this . _editorFrame ) {
180171 const frameRect = this . _editorFrame . getBoundingClientRect ( ) ;
0 commit comments