4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { Event } from '../../base/common/event.js' ;
7
- import { Disposable , DisposableStore } from '../../base/common/lifecycle.js' ;
7
+ import { Disposable , DisposableStore , MutableDisposable } from '../../base/common/lifecycle.js' ;
8
8
import { IContextKeyService , IContextKey , setConstant as setConstantContextKey } from '../../platform/contextkey/common/contextkey.js' ;
9
9
import { InputFocusedContext , IsMacContext , IsLinuxContext , IsWindowsContext , IsWebContext , IsMacNativeContext , IsDevelopmentContext , IsIOSContext , ProductQualityContext , IsMobileContext } from '../../platform/contextkey/common/contextkeys.js' ;
10
10
import { SplitEditorsVertically , InEditorZenModeContext , AuxiliaryBarVisibleContext , SideBarVisibleContext , PanelAlignmentContext , PanelMaximizedContext , PanelVisibleContext , EmbedderIdentifierContext , EditorTabsVisibleContext , IsMainEditorCenteredLayoutContext , MainEditorAreaVisibleContext , DirtyWorkingCopiesContext , EmptyWorkspaceSupportContext , EnterMultiRootWorkspaceSupportContext , HasWebFileSystemAccess , IsMainWindowFullscreenContext , OpenFolderWorkspaceSupportContext , RemoteNameContext , VirtualWorkspaceContext , WorkbenchStateContext , WorkspaceFolderCountContext , PanelPositionContext , TemporaryWorkspaceContext , TitleBarVisibleContext , TitleBarStyleContext , IsAuxiliaryWindowFocusedContext , ActiveEditorGroupEmptyContext , ActiveEditorGroupIndexContext , ActiveEditorGroupLastContext , ActiveEditorGroupLockedContext , MultipleEditorGroupsContext , EditorsVisibleContext , AuxiliaryBarMaximizedContext } from '../common/contextkeys.js' ;
@@ -219,7 +219,11 @@ export class WorkbenchContextKeysHandler extends Disposable {
219
219
220
220
this . _register ( this . editorGroupService . onDidChangeEditorPartOptions ( ( ) => this . updateEditorAreaContextKeys ( ) ) ) ;
221
221
222
- this . _register ( Event . runAndSubscribe ( onDidRegisterWindow , ( { window, disposables } ) => disposables . add ( addDisposableListener ( window , EventType . FOCUS_IN , ( ) => this . updateInputContextKeys ( window . document , disposables ) , true ) ) , { window : mainWindow , disposables : this . _store } ) ) ;
222
+
223
+ this . _register ( Event . runAndSubscribe ( onDidRegisterWindow , ( { window, disposables } ) => {
224
+ const mutableDisposable = disposables . add ( new MutableDisposable ( ) ) ;
225
+ disposables . add ( addDisposableListener ( window , EventType . FOCUS_IN , ( ) => this . updateInputContextKeys ( window . document , mutableDisposable ) , true ) ) ;
226
+ } , { window : mainWindow , disposables : this . _store } ) ) ;
223
227
224
228
this . _register ( this . contextService . onDidChangeWorkbenchState ( ( ) => this . updateWorkbenchStateContextKey ( ) ) ) ;
225
229
this . _register ( this . contextService . onDidChangeWorkspaceFolders ( ( ) => {
@@ -305,7 +309,7 @@ export class WorkbenchContextKeysHandler extends Disposable {
305
309
this . editorTabsVisibleContext . set ( this . editorGroupService . partOptions . showTabs === 'multiple' ) ;
306
310
}
307
311
308
- private updateInputContextKeys ( ownerDocument : Document , disposables : DisposableStore ) : void {
312
+ private updateInputContextKeys ( ownerDocument : Document , mutableDisposable : MutableDisposable < any > ) : void {
309
313
310
314
function activeElementIsInput ( ) : boolean {
311
315
return ! ! ownerDocument . activeElement && isEditableElement ( ownerDocument . activeElement ) ;
@@ -314,8 +318,14 @@ export class WorkbenchContextKeysHandler extends Disposable {
314
318
const isInputFocused = activeElementIsInput ( ) ;
315
319
this . inputFocusedContext . set ( isInputFocused ) ;
316
320
321
+
322
+ const store = new DisposableStore ( ) ;
323
+ mutableDisposable . value = store ;
324
+
325
+
317
326
if ( isInputFocused ) {
318
- const tracker = disposables . add ( trackFocus ( ownerDocument . activeElement as HTMLElement ) ) ;
327
+
328
+ const tracker = store . add ( trackFocus ( ownerDocument . activeElement as HTMLElement ) ) ;
319
329
Event . once ( tracker . onDidBlur ) ( ( ) => {
320
330
321
331
// Ensure we are only updating the context key if we are
@@ -331,7 +341,7 @@ export class WorkbenchContextKeysHandler extends Disposable {
331
341
}
332
342
333
343
tracker . dispose ( ) ;
334
- } , undefined , disposables ) ;
344
+ } , undefined , store ) ;
335
345
}
336
346
}
337
347
0 commit comments