From 2ca50c08f3725d31c9717083844eaed78ba8b94f Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 24 Jul 2017 10:42:35 +0530 Subject: [PATCH] Fix #31146 --- .../preferences/browser/preferencesEditor.ts | 27 ++++++++++++++++--- .../preferences/browser/preferencesWidgets.ts | 11 +++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts index c0ab452bb1e..3b7fdd5a415 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts @@ -57,6 +57,7 @@ import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRe import { attachStylerCallback } from 'vs/platform/theme/common/styler'; import { scrollbarShadow } from 'vs/platform/theme/common/colorRegistry'; import { IWorkspaceContextService } from "vs/platform/workspace/common/workspace"; +import Event, { Emitter } from "vs/base/common/event"; export class PreferencesEditorInput extends SideBySideEditorInput { public static ID: string = 'workbench.editorinputs.preferencesEditorInput'; @@ -112,6 +113,7 @@ export class PreferencesEditor extends BaseEditor { private delayedFilterLogging: Delayer; private latestEmptyFilters: string[] = []; + private lastFocusedWidget: SearchWidget | SideBySidePreferencesWidget = null; constructor( @IPreferencesService private preferencesService: IPreferencesService, @@ -142,12 +144,16 @@ export class PreferencesEditor extends BaseEditor { })); this._register(this.searchWidget.onDidChange(value => this.filterPreferences(value.trim()))); this._register(this.searchWidget.onNavigate(shift => this.preferencesRenderers.focusNextPreference(!shift))); + this._register(this.searchWidget.onFocus(() => this.lastFocusedWidget = this.searchWidget)); + this.lastFocusedWidget = this.searchWidget; this.settingsTargetsWidget = this._register(this.instantiationService.createInstance(SettingsTargetsWidget, this.headerContainer, this.preferencesService.userSettingsResource)); this._register(this.settingsTargetsWidget.onDidTargetChange(target => this.switchSettings(target))); const editorsContainer = DOM.append(parentElement, DOM.$('.preferences-editors-container')); this.sideBySidePreferencesWidget = this._register(this.instantiationService.createInstance(SideBySidePreferencesWidget, editorsContainer)); + this._register(this.sideBySidePreferencesWidget.onFocus(() => this.lastFocusedWidget = this.sideBySidePreferencesWidget)); + this.preferencesRenderers = this._register(new PreferencesRenderers()); } @@ -169,7 +175,9 @@ export class PreferencesEditor extends BaseEditor { } public focus(): void { - this.searchWidget.focus(); + if (this.lastFocusedWidget) { + this.lastFocusedWidget.focus(); + } } public focusSearch(filter?: string): void { @@ -405,10 +413,15 @@ class SideBySidePreferencesWidget extends Widget { private dimension: Dimension; private defaultPreferencesEditor: DefaultPreferencesEditor; + private editablePreferencesEditor: EditableSettingsEditor; private defaultPreferencesEditorContainer: HTMLElement; - private editablePreferencesEditor: BaseEditor; private editablePreferencesEditorContainer: HTMLElement; + private _onFocus: Emitter = new Emitter(); + readonly onFocus: Event = this._onFocus.event; + + private lastFocusedEditor: BaseEditor; + private sash: VSash; constructor(parent: HTMLElement, @IInstantiationService private instantiationService: IInstantiationService, @IThemeService private themeService: IThemeService) { @@ -425,12 +438,15 @@ class SideBySidePreferencesWidget extends Widget { this.defaultPreferencesEditor = this._register(this.instantiationService.createInstance(DefaultPreferencesEditor)); this.defaultPreferencesEditor.create(new Builder(this.defaultPreferencesEditorContainer)); this.defaultPreferencesEditor.setVisible(true); + (this.defaultPreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.defaultPreferencesEditor); this.editablePreferencesEditorContainer = DOM.append(parentElement, DOM.$('.editable-preferences-editor-container')); this.editablePreferencesEditorContainer.style.position = 'absolute'; this.editablePreferencesEditor = this._register(this.instantiationService.createInstance(EditableSettingsEditor)); this.editablePreferencesEditor.create(new Builder(this.editablePreferencesEditorContainer)); this.editablePreferencesEditor.setVisible(true); + (this.editablePreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.editablePreferencesEditor); + this.lastFocusedEditor = this.editablePreferencesEditor; this._register(attachStylerCallback(this.themeService, { scrollbarShadow }, colors => { const shadow = colors.scrollbarShadow ? colors.scrollbarShadow.toString() : null; @@ -441,6 +457,9 @@ class SideBySidePreferencesWidget extends Widget { this.editablePreferencesEditorContainer.style.boxShadow = null; } })); + + const focusTracker = this._register(DOM.trackFocus(parentElement)); + this._register(focusTracker.addFocusListener(() => this._onFocus.fire())); } public setInput(defaultPreferencesEditorInput: DefaultPreferencesEditorInput, editablePreferencesEditorInput: EditorInput, options?: EditorOptions): TPromise<{ defaultPreferencesRenderer: IPreferencesRenderer, editablePreferencesRenderer: IPreferencesRenderer }> { @@ -456,8 +475,8 @@ class SideBySidePreferencesWidget extends Widget { } public focus(): void { - if (this.editablePreferencesEditor) { - this.editablePreferencesEditor.focus(); + if (this.lastFocusedEditor) { + this.lastFocusedEditor.focus(); } } diff --git a/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts b/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts index 7f15c197c24..94abdd28880 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesWidgets.ts @@ -384,12 +384,15 @@ export class SearchWidget extends Widget { private searchContainer: HTMLElement; private inputBox: InputBox; - private _onDidChange = this._register(new Emitter()); + private _onDidChange: Emitter = this._register(new Emitter()); public readonly onDidChange: Event = this._onDidChange.event; - private _onNavigate = this._register(new Emitter()); + private _onNavigate: Emitter = this._register(new Emitter()); public readonly onNavigate: Event = this._onNavigate.event; + private _onFocus: Emitter = this._register(new Emitter()); + public readonly onFocus: Event = this._onFocus.event; + constructor(parent: HTMLElement, protected options: SearchOptions, @IContextViewService private contextViewService: IContextViewService, @IContextMenuService private contextMenuService: IContextMenuService, @@ -418,8 +421,10 @@ export class SearchWidget extends Widget { })); this.inputBox.inputElement.setAttribute('aria-live', 'assertive'); + const focusTracker = this._register(DOM.trackFocus(this.inputBox.inputElement)); + this._register(focusTracker.addFocusListener(() => this._onFocus.fire())); + if (this.options.focusKey) { - const focusTracker = this._register(DOM.trackFocus(this.inputBox.inputElement)); this._register(focusTracker.addFocusListener(() => this.options.focusKey.set(true))); this._register(focusTracker.addBlurListener(() => this.options.focusKey.set(false))); } -- GitLab