Skip to content

Commit e39072b

Browse files
committed
keyboard layout service is async in browser
1 parent e9a657d commit e39072b

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/vs/workbench/services/keybinding/browser/keyboardLayoutProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ export class KeyboardLayoutProvider {
224224

225225
private _layoutInfos: KeyboardLayoutInfo[] = [];
226226
// private _mru: KeyboardLayoutInfo[] = [];
227-
private _active: KeyboardLayoutInfo;
227+
private _active: KeyboardLayoutInfo | null;
228228

229229
private constructor() {
230-
this._active = EN_US;
230+
this._active = null;
231231
}
232232

233233
registerKeyboardLayout(layout: KeyboardLayoutInfo) {
@@ -246,15 +246,15 @@ export class KeyboardLayoutProvider {
246246
this._active = this.getMatchedKeyboardLayout(keymap);
247247
}
248248

249-
getMatchedKeyboardLayout(keymap: IKeyboardMapping): KeyboardLayoutInfo {
249+
getMatchedKeyboardLayout(keymap: IKeyboardMapping): KeyboardLayoutInfo | null {
250250
// TODO go through mru list instead of _layoutInfos
251251
for (let i = 0; i < this._layoutInfos.length; i++) {
252252
if (this._layoutInfos[i].fuzzyEqual(keymap)) {
253253
return this._layoutInfos[i];
254254
}
255255
}
256256

257-
return EN_US;
257+
return null;
258258
}
259259

260260
getKeyboardLayouts(): KeyboardLayoutInfo[] {

src/vs/workbench/services/keybinding/browser/keyboardLayoutService.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ export class BrowserKeyboardMapperFactory {
6565

6666
this.getBrowserKeyMap().then(keyMap => {
6767
KeyboardLayoutProvider.INSTANCE.setActive(keyMap);
68-
let currentKeyboardLayout = KeyboardLayoutProvider.INSTANCE.activeKeyboardLayout.layout;
69-
this._setKeyboardData(currentKeyboardLayout, keyMap);
68+
let currentKeyboardLayout = KeyboardLayoutProvider.INSTANCE.activeKeyboardLayout;
69+
70+
if (currentKeyboardLayout) {
71+
this._setKeyboardData(currentKeyboardLayout.layout, keyMap);
72+
}
7073
});
7174
}
7275

@@ -110,6 +113,10 @@ export class BrowserKeyboardMapperFactory {
110113

111114
const standardKeyboardEvent = keyboardEvent as StandardKeyboardEvent;
112115
const currentKeymap = KeyboardLayoutProvider.INSTANCE.activeKeyboardLayout;
116+
if (!currentKeymap) {
117+
return true;
118+
}
119+
113120
const mapping = currentKeymap.value[standardKeyboardEvent.code];
114121

115122
if (!mapping) {
@@ -207,7 +214,13 @@ export class BrowserKeyboardMapperFactory {
207214
};
208215
}
209216

210-
return KeyboardLayoutProvider.INSTANCE.getMatchedKeyboardLayout(ret).value;
217+
const matchedKeyboardLayout = KeyboardLayoutProvider.INSTANCE.getMatchedKeyboardLayout(ret);
218+
219+
if (matchedKeyboardLayout) {
220+
return matchedKeyboardLayout.value;
221+
}
222+
223+
return {};
211224
});
212225
}
213226

0 commit comments

Comments
 (0)