mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-05 20:08:58 -05:00
fixes #39855
This commit is contained in:
@@ -253,6 +253,10 @@ class TraitSpliceable<T> implements ISpliceable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
function isInputElement(e: HTMLElement): boolean {
|
||||
return e.tagName === 'INPUT' || e.tagName === 'TEXTAREA';
|
||||
}
|
||||
|
||||
class KeyboardController<T> implements IDisposable {
|
||||
|
||||
private disposables: IDisposable[];
|
||||
@@ -266,7 +270,8 @@ class KeyboardController<T> 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);
|
||||
|
||||
@@ -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<any> | PagedList<any> | ITree;
|
||||
|
||||
@@ -72,14 +72,14 @@ export class ListService implements IListService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const WorkbenchListFocusContextKey = new RawContextKey<boolean>('listFocus', true);
|
||||
const RawWorkbenchListFocusContextKey = new RawContextKey<boolean>('listFocus', true);
|
||||
export const WorkbenchListFocusContextKey = ContextKeyExpr.and(RawWorkbenchListFocusContextKey, ContextKeyExpr.not(InputFocusedContextKey));
|
||||
|
||||
export type Widget = List<any> | PagedList<any> | 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<boolean> = this._onFocusChange.event;
|
||||
|
||||
readonly contextKeyService: IContextKeyService;
|
||||
private workbenchListFocusContextKey: IContextKey<boolean>;
|
||||
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 {
|
||||
|
||||
11
src/vs/platform/workbench/common/contextkeys.ts
Normal file
11
src/vs/platform/workbench/common/contextkeys.ts
Normal file
@@ -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<boolean>(InputFocusedContextKey, false);
|
||||
@@ -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<boolean>('globalMessageVisible', false);
|
||||
export const EditorsVisibleContext = new RawContextKey<boolean>('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<string>('workbenchState', getWorkbenchStateString(this.configurationService.getWorkbenchState()));
|
||||
const workbenchStateContext = WorkbenchStateContext.bindTo(this.contextKeyService);
|
||||
|
||||
Reference in New Issue
Block a user