From 9bc5332d797294c3e7ee14763b232bef7c156ba6 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Fri, 21 Jun 2019 13:38:40 -0700 Subject: [PATCH] Separate keyboard layout loading logic for testing --- .../keybinding/browser/keymapService.ts | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/services/keybinding/browser/keymapService.ts b/src/vs/workbench/services/keybinding/browser/keymapService.ts index 13434bdb7bb..21546ac6d36 100644 --- a/src/vs/workbench/services/keybinding/browser/keymapService.ts +++ b/src/vs/workbench/services/keybinding/browser/keymapService.ts @@ -28,17 +28,16 @@ import { Extensions as ConfigExtensions, IConfigurationRegistry, IConfigurationN import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { INavigatorWithKeyboard } from 'vs/workbench/services/keybinding/common/navigatorKeyboard'; -export class BrowserKeyboardMapperFactory { - public static readonly INSTANCE = new BrowserKeyboardMapperFactory(); +export class BrowserKeyboardMapperFactoryBase { // keyboard mapper - private _initialized: boolean; - private _keyboardMapper: IKeyboardMapper | null; + protected _initialized: boolean; + protected _keyboardMapper: IKeyboardMapper | null; private readonly _onDidChangeKeyboardMapper = new Emitter(); public readonly onDidChangeKeyboardMapper: Event = this._onDidChangeKeyboardMapper.event; // keymap infos - private _keymapInfos: KeymapInfo[]; - private _mru: KeymapInfo[]; + protected _keymapInfos: KeymapInfo[]; + protected _mru: KeymapInfo[]; private _activeKeymapInfo: KeymapInfo | null; get activeKeymap(): KeymapInfo | null { @@ -69,23 +68,13 @@ export class BrowserKeyboardMapperFactory { return this._keymapInfos.map(keymapInfo => keymapInfo.layout); } - private constructor() { + protected constructor() { this._keyboardMapper = null; this._initialized = false; this._keymapInfos = []; this._mru = []; this._activeKeymapInfo = null; - const platform = isWindows ? 'win' : isMacintosh ? 'darwin' : 'linux'; - - import('vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.' + platform).then((m) => { - let keymapInfos: IKeymapInfo[] = m.KeyboardLayoutContribution.INSTANCE.layoutInfos; - this._keymapInfos.push(...keymapInfos.map(info => (new KeymapInfo(info.layout, info.secondaryLayouts, info.mapping, info.isUserKeyboardLayout)))); - this._mru = this._keymapInfos; - this._initialized = true; - this.onKeyboardLayoutChanged(); - }); - if ((navigator).keyboard && (navigator).keyboard.addEventListener) { (navigator).keyboard.addEventListener!('layoutchange', () => { // Update user keyboard map settings @@ -371,6 +360,25 @@ export class BrowserKeyboardMapperFactory { //#endregion } +export class BrowserKeyboardMapperFactory extends BrowserKeyboardMapperFactoryBase { + public static readonly INSTANCE = new BrowserKeyboardMapperFactory(); + // keyboard mapper + + private constructor() { + super(); + + const platform = isWindows ? 'win' : isMacintosh ? 'darwin' : 'linux'; + + import('vs/workbench/services/keybinding/browser/keyboardLayouts/layout.contribution.' + platform).then((m) => { + let keymapInfos: IKeymapInfo[] = m.KeyboardLayoutContribution.INSTANCE.layoutInfos; + this._keymapInfos.push(...keymapInfos.map(info => (new KeymapInfo(info.layout, info.secondaryLayouts, info.mapping, info.isUserKeyboardLayout)))); + this._mru = this._keymapInfos; + this._initialized = true; + this.onKeyboardLayoutChanged(); + }); + } +} + class UserKeyboardLayout extends Disposable { private readonly reloadConfigurationScheduler: RunOnceScheduler; protected readonly _onDidChange: Emitter = this._register(new Emitter()); -- GitLab