Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/keybinding/common/fallbackKeyboardMapper.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { ResolvedKeybinding, KeyCodeChord, Keybinding } from '../../../../base/common/keybindings.js';
7
import { OperatingSystem } from '../../../../base/common/platform.js';
8
import { IKeyboardEvent } from '../../../../platform/keybinding/common/keybinding.js';
9
import { USLayoutResolvedKeybinding } from '../../../../platform/keybinding/common/usLayoutResolvedKeybinding.js';
10
import { IKeyboardMapper } from '../../../../platform/keyboardLayout/common/keyboardMapper.js';
11
12
/**
13
* A keyboard mapper to be used when reading the keymap from the OS fails.
14
*/
15
export class FallbackKeyboardMapper implements IKeyboardMapper {
16
17
constructor(
18
private readonly _mapAltGrToCtrlAlt: boolean,
19
private readonly _OS: OperatingSystem,
20
) { }
21
22
public dumpDebugInfo(): string {
23
return 'FallbackKeyboardMapper dispatching on keyCode';
24
}
25
26
public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
27
const ctrlKey = keyboardEvent.ctrlKey || (this._mapAltGrToCtrlAlt && keyboardEvent.altGraphKey);
28
const altKey = keyboardEvent.altKey || (this._mapAltGrToCtrlAlt && keyboardEvent.altGraphKey);
29
const chord = new KeyCodeChord(
30
ctrlKey,
31
keyboardEvent.shiftKey,
32
altKey,
33
keyboardEvent.metaKey,
34
keyboardEvent.keyCode
35
);
36
const result = this.resolveKeybinding(new Keybinding([chord]));
37
return result[0];
38
}
39
40
public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
41
return USLayoutResolvedKeybinding.resolveKeybinding(keybinding, this._OS);
42
}
43
}
44
45