diff --git a/src/vs/base/browser/ui/list/listWidget.ts b/src/vs/base/browser/ui/list/listWidget.ts index f859a3fd02640d76ee8cf09f4ea1ef179727aa71..2222d02d82491fc6241bb20f6d7369629ec2094b 100644 --- a/src/vs/base/browser/ui/list/listWidget.ts +++ b/src/vs/base/browser/ui/list/listWidget.ts @@ -253,6 +253,10 @@ class TraitSpliceable implements ISpliceable { } } +function isInputElement(e: HTMLElement): boolean { + return e.tagName === 'INPUT' || e.tagName === 'TEXTAREA'; +} + class KeyboardController implements IDisposable { private disposables: IDisposable[]; @@ -266,7 +270,8 @@ class KeyboardController implements IDisposable { this.disposables = []; const onKeyDown = chain(domEvent(view.domNode, 'keydown')) - .map(e => new StandardKeyboardEvent(e)); + .map(e => new StandardKeyboardEvent(e)) + .filter(e => !isInputElement(e.target)); onKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(this.onEnter, this, this.disposables); onKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this, this.disposables); diff --git a/src/vs/platform/list/browser/listService.ts b/src/vs/platform/list/browser/listService.ts index b28316f0b5be9f8c5218f0372dac3ef00d423838..b4d344e30acd87f8195c8564c622aa4a816c2931 100644 --- a/src/vs/platform/list/browser/listService.ts +++ b/src/vs/platform/list/browser/listService.ts @@ -8,14 +8,14 @@ import { ITree, ITreeConfiguration, ITreeOptions } from 'vs/base/parts/tree/brow import { List, IListOptions } from 'vs/base/browser/ui/list/listWidget'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IDisposable, toDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecycle'; -import { IContextKeyService, IContextKey, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { IContextKeyService, IContextKey, RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { PagedList, IPagedRenderer } from 'vs/base/browser/ui/list/listPaging'; import { IDelegate, IRenderer } from 'vs/base/browser/ui/list/list'; import { Tree } from 'vs/base/parts/tree/browser/treeImpl'; import { attachListStyler } from 'vs/platform/theme/common/styler'; import { IThemeService } from 'vs/platform/theme/common/themeService'; -import { debounce } from 'vs/base/common/decorators'; import Event, { Emitter } from 'vs/base/common/event'; +import { InputFocusedContextKey } from 'vs/platform/workbench/common/contextkeys'; export type ListWidget = List | PagedList | ITree; @@ -72,14 +72,14 @@ export class ListService implements IListService { } } - -export const WorkbenchListFocusContextKey = new RawContextKey('listFocus', true); +const RawWorkbenchListFocusContextKey = new RawContextKey('listFocus', true); +export const WorkbenchListFocusContextKey = ContextKeyExpr.and(RawWorkbenchListFocusContextKey, ContextKeyExpr.not(InputFocusedContextKey)); export type Widget = List | PagedList | ITree; function createScopedContextKeyService(contextKeyService: IContextKeyService, widget: Widget): IContextKeyService { const result = contextKeyService.createScoped(widget.getHTMLElement()); - WorkbenchListFocusContextKey.bindTo(result); + RawWorkbenchListFocusContextKey.bindTo(result); return result; } @@ -147,7 +147,6 @@ export class WorkbenchTree extends Tree { readonly onFocusChange: Event = this._onFocusChange.event; readonly contextKeyService: IContextKeyService; - private workbenchListFocusContextKey: IContextKey; private disposables: IDisposable[] = []; constructor( @@ -160,26 +159,13 @@ export class WorkbenchTree extends Tree { ) { super(container, configuration, options); - this.contextKeyService = contextKeyService.createScoped(this.getHTMLElement()); - this.workbenchListFocusContextKey = WorkbenchListFocusContextKey.bindTo(this.contextKeyService); + this.contextKeyService = createScopedContextKeyService(contextKeyService, this); this.disposables.push( this.contextKeyService, (listService as ListService).register(this), attachListStyler(this, themeService) ); - - this.onDidFocus(this.updateContextKey, this, this.disposables); - this.onDidBlur(this.updateContextKey, this, this.disposables); - this.onDidChangeHighlight(this.updateContextKey, this, this.disposables); - } - - @debounce(50) - private updateContextKey(): void { - const isFocused = document.activeElement === this.getHTMLElement(); - - this.workbenchListFocusContextKey.set(isFocused); - this._onFocusChange.fire(isFocused); } dispose(): void { diff --git a/src/vs/platform/workbench/common/contextkeys.ts b/src/vs/platform/workbench/common/contextkeys.ts new file mode 100644 index 0000000000000000000000000000000000000000..c4a740d8c28b9f994622fd963e0b6cfb98ffea5a --- /dev/null +++ b/src/vs/platform/workbench/common/contextkeys.ts @@ -0,0 +1,11 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; + +export const InputFocusedContextKey = 'inputFocus'; +export const InputFocusedContext = new RawContextKey(InputFocusedContextKey, false); \ No newline at end of file diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 17a43e6ea7a88546a097e371f9fbe95b668ec7f2..946ac23fa9dbc2d4baf272ac9ee89b8b4ec7d66b 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -96,6 +96,8 @@ import { IDecorationsService } from 'vs/workbench/services/decorations/browser/d import { ActivityService } from 'vs/workbench/services/activity/browser/activityService'; import URI from 'vs/base/common/uri'; import { IListService, ListService } from 'vs/platform/list/browser/listService'; +import { domEvent } from 'vs/base/browser/event'; +import { InputFocusedContext } from 'vs/platform/workbench/common/contextkeys'; export const MessagesVisibleContext = new RawContextKey('globalMessageVisible', false); export const EditorsVisibleContext = new RawContextKey('editorIsOpen', false); @@ -277,6 +279,10 @@ export class Workbench implements IPartService { this.inZenMode = InZenModeContext.bindTo(this.contextKeyService); this.sideBarVisibleContext = SidebarVisibleContext.bindTo(this.contextKeyService); + const inputFocused = InputFocusedContext.bindTo(this.contextKeyService); + const onWindowsFocusIn = domEvent(window, 'focusin', true); + onWindowsFocusIn(() => inputFocused.set(document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA'), null, this.toDispose); + // Set workbench state context const WorkbenchStateContext = new RawContextKey('workbenchState', getWorkbenchStateString(this.configurationService.getWorkbenchState())); const workbenchStateContext = WorkbenchStateContext.bindTo(this.contextKeyService);