Skip to content

Commit da4bbf3

Browse files
authored
aux window - track input focus properly (fix microsoft#199729) (microsoft#199840)
aux window - track input focus properly (microsoft#199729)
1 parent 6afa800 commit da4bbf3

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/vs/workbench/browser/contextkeys.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IContextKeyService, IContextKey, setConstant as setConstantContextKey }
99
import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext, IsWebContext, IsMacNativeContext, IsDevelopmentContext, IsIOSContext, ProductQualityContext, IsMobileContext } from 'vs/platform/contextkey/common/contextkeys';
1010
import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, MainEditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, ActiveEditorCanToggleReadonlyContext, applyAvailableEditorIds, TitleBarVisibleContext, TitleBarStyleContext, MultipleEditorGroupsContext, IsAuxiliaryWindowFocusedContext } from 'vs/workbench/common/contextkeys';
1111
import { TEXT_DIFF_EDITOR_ID, EditorInputCapabilities, SIDE_BY_SIDE_EDITOR_ID, EditorResourceAccessor, SideBySideEditor } from 'vs/workbench/common/editor';
12-
import { trackFocus, addDisposableListener, EventType, onDidRegisterWindow } from 'vs/base/browser/dom';
12+
import { trackFocus, addDisposableListener, EventType, onDidRegisterWindow, getActiveWindow } from 'vs/base/browser/dom';
1313
import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
1414
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1515
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
@@ -348,7 +348,18 @@ export class WorkbenchContextKeysHandler extends Disposable {
348348
if (isInputFocused) {
349349
const tracker = trackFocus(ownerDocument.activeElement as HTMLElement);
350350
Event.once(tracker.onDidBlur)(() => {
351-
this.inputFocusedContext.set(activeElementIsInput());
351+
352+
// Ensure we are only updating the context key if we are
353+
// still in the same document that we are tracking. This
354+
// fixes a race condition in multi-window setups where
355+
// the blur event arrives in the inactive window overwriting
356+
// the context key of the active window. This is because
357+
// blur events from the focus tracker are emitted with a
358+
// timeout of 0.
359+
360+
if (getActiveWindow().document === ownerDocument) {
361+
this.inputFocusedContext.set(activeElementIsInput());
362+
}
352363

353364
tracker.dispose();
354365
});

0 commit comments

Comments
 (0)