src/vs/platform/keybinding/common/usLayoutResolvedKeybinding.ts

194 LOC · 186 covered · 8 uncovered · 74 ranges · 1386 concepts · 30 introducers · 699 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- usLayoutResolvedKeybinding.ts ×14
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 { KeyCode, KeyCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE, ScanCode } from '../../../base/common/keyCodes.js';
7 > import { SingleModifierChord, Chord, KeyCodeChord, Keybinding } from '../../../base/common/keybindings.js';
8 > import { OperatingSystem } from '../../../base/common/platform.js';
9 > import { BaseResolvedKeybinding } from './baseResolvedKeybinding.js';
10 > import { toEmptyArrayIfContainsNull } from './resolvedKeybindingItem.js';
11 >
12 > /**
13 > * Do not instantiate. Use KeybindingService to get a ResolvedKeybinding seeded with information about the current kb layout.
14 > */
15 > export class USLayoutResolvedKeybinding extends BaseResolvedKeybinding<KeyCodeChord> {
16 >
17 > constructor(chords: KeyCodeChord[], os: OperatingSystem) {
18 > super(os, chords); usLayoutResolvedKeybinding.ts ×1
19 > }
21 > private _keyCodeToUILabel(keyCode: KeyCode): string {
22 > if (this._os === OperatingSystem.Macintosh) { usLayoutResolvedKeybinding.ts ×3
23 > switch (keyCode) { usLayoutResolvedKeybinding.ts ×5
24 > case KeyCode.LeftArrow:
26 > case KeyCode.UpArrow: usLayoutResolvedKeybinding.ts ×5
28 > case KeyCode.RightArrow: usLayoutResolvedKeybinding.ts ×5
30 > case KeyCode.DownArrow: usLayoutResolvedKeybinding.ts ×5
33 > }
34 > return KeyCodeUtils.toString(keyCode); usLayoutResolvedKeybinding.ts ×3
35 > }
37 > protected _getLabel(chord: KeyCodeChord): string | null {
38 > if (chord.isDuplicateModifierCase()) { usLayoutResolvedKeybinding.ts ×2
40 > }
41 > return this._keyCodeToUILabel(chord.keyCode); usLayoutResolvedKeybinding.ts ×3
44 > protected _getAriaLabel(chord: KeyCodeChord): string | null {
45 > if (chord.isDuplicateModifierCase()) { usLayoutResolvedKeybinding.ts ×2
47 > }
48 > return KeyCodeUtils.toString(chord.keyCode); usLayoutResolvedKeybinding.ts ×1
51 > protected _getElectronAccelerator(chord: KeyCodeChord): string | null {
52 > return KeyCodeUtils.toElectronAccelerator(chord.keyCode); usLayoutResolvedKeybinding.ts ×1
53 > }
55 > protected _getUserSettingsLabel(chord: KeyCodeChord): string | null {
56 > if (chord.isDuplicateModifierCase()) { usLayoutResolvedKeybinding.ts ×2
58 > }
59 > const result = KeyCodeUtils.toUserSettingsUS(chord.keyCode); usLayoutResolvedKeybinding.ts ×1
60 > return (result ? result.toLowerCase() : result); usLayoutResolvedKeybinding.ts ×2
61 > }
63 > protected _isWYSIWYG(): boolean {
64 > return true; fallbackKeyboardMapper.ts ×3
65 > }
67 > protected _getChordDispatch(chord: KeyCodeChord): string | null {
68 > return USLayoutResolvedKeybinding.getDispatchStr(chord); usLayoutResolvedKeybinding.ts ×3
69 > }
71 > public static getDispatchStr(chord: KeyCodeChord): string | null {
72 > if (chord.isModifierKey()) { usLayoutResolvedKeybinding.ts ×3
74 > }
75 > let result = ''; usLayoutResolvedKeybinding.ts ×5
76 >
77 > if (chord.ctrlKey) {
78 > result += 'ctrl+'; usLayoutResolvedKeybinding.ts ×1
79 > }
80 > if (chord.shiftKey) { usLayoutResolvedKeybinding.ts ×5
81 > result += 'shift+'; usLayoutResolvedKeybinding.ts ×1
82 > }
83 > if (chord.altKey) { usLayoutResolvedKeybinding.ts ×5
84 > result += 'alt+'; usLayoutResolvedKeybinding.ts ×1
85 > }
86 > if (chord.metaKey) { usLayoutResolvedKeybinding.ts ×5
87 > result += 'meta+'; usLayoutResolvedKeybinding.ts ×1
88 > }
89 > result += KeyCodeUtils.toString(chord.keyCode); usLayoutResolvedKeybinding.ts ×5
90 >
91 > return result;
94 > protected _getSingleModifierChordDispatch(keybinding: KeyCodeChord): SingleModifierChord | null {
95 > if (keybinding.keyCode === KeyCode.Ctrl && !keybinding.shiftKey && !keybinding.altKey && !keybinding.metaKey) { usLayoutResolvedKeybinding.ts ×5
96 > return 'ctrl'; usLayoutResolvedKeybinding.ts ×1
97 > }
98 > if (keybinding.keyCode === KeyCode.Shift && !keybinding.ctrlKey && !keybinding.altKey && !keybinding.metaKey) { usLayoutResolvedKeybinding.ts ×5
99 > return 'shift'; usLayoutResolvedKeybinding.ts ×1
100 > }
101 > if (keybinding.keyCode === KeyCode.Alt && !keybinding.ctrlKey && !keybinding.shiftKey && !keybinding.metaKey) { usLayoutResolvedKeybinding.ts ×5
102 > return 'alt'; usLayoutResolvedKeybinding.ts ×1
103 > }
104 > if (keybinding.keyCode === KeyCode.Meta && !keybinding.ctrlKey && !keybinding.shiftKey && !keybinding.altKey) { usLayoutResolvedKeybinding.ts ×5
105 > return 'meta'; usLayoutResolvedKeybinding.ts ×1
106 > }
110 > /**
111 > * *NOTE*: Check return value for `KeyCode.Unknown`.
112 > */
113 > private static _scanCodeToKeyCode(scanCode: ScanCode): KeyCode {
114 > const immutableKeyCode = IMMUTABLE_CODE_TO_KEY_CODE[scanCode]; usLayoutResolvedKeybinding.ts ×5
115 > if (immutableKeyCode !== KeyCode.DependsOnKbLayout) {
116 return immutableKeyCode;
117 }
119 > switch (scanCode) {
120 > case ScanCode.KeyA: return KeyCode.KeyA;
121 > case ScanCode.KeyB: return KeyCode.KeyB;
122 > case ScanCode.KeyC: return KeyCode.KeyC;
123 > case ScanCode.KeyD: return KeyCode.KeyD;
124 > case ScanCode.KeyE: return KeyCode.KeyE;
125 > case ScanCode.KeyF: return KeyCode.KeyF;
126 > case ScanCode.KeyG: return KeyCode.KeyG;
127 > case ScanCode.KeyH: return KeyCode.KeyH;
128 > case ScanCode.KeyI: return KeyCode.KeyI;
129 > case ScanCode.KeyJ: return KeyCode.KeyJ;
130 > case ScanCode.KeyK: return KeyCode.KeyK;
131 > case ScanCode.KeyL: return KeyCode.KeyL;
132 > case ScanCode.KeyM: return KeyCode.KeyM;
133 > case ScanCode.KeyN: return KeyCode.KeyN;
134 > case ScanCode.KeyO: return KeyCode.KeyO;
135 > case ScanCode.KeyP: return KeyCode.KeyP;
136 > case ScanCode.KeyQ: return KeyCode.KeyQ;
137 > case ScanCode.KeyR: return KeyCode.KeyR;
138 > case ScanCode.KeyS: return KeyCode.KeyS;
139 > case ScanCode.KeyT: return KeyCode.KeyT;
140 > case ScanCode.KeyU: return KeyCode.KeyU;
141 > case ScanCode.KeyV: return KeyCode.KeyV;
142 > case ScanCode.KeyW: return KeyCode.KeyW;
143 > case ScanCode.KeyX: return KeyCode.KeyX;
144 > case ScanCode.KeyY: return KeyCode.KeyY;
145 > case ScanCode.KeyZ: return KeyCode.KeyZ;
146 > case ScanCode.Digit1: return KeyCode.Digit1;
147 > case ScanCode.Digit2: return KeyCode.Digit2;
148 > case ScanCode.Digit3: return KeyCode.Digit3;
149 > case ScanCode.Digit4: return KeyCode.Digit4;
150 > case ScanCode.Digit5: return KeyCode.Digit5;
151 > case ScanCode.Digit6: return KeyCode.Digit6;
152 > case ScanCode.Digit7: return KeyCode.Digit7;
153 > case ScanCode.Digit8: return KeyCode.Digit8;
154 > case ScanCode.Digit9: return KeyCode.Digit9;
155 > case ScanCode.Digit0: return KeyCode.Digit0;
156 > case ScanCode.Minus: return KeyCode.Minus;
157 > case ScanCode.Equal: return KeyCode.Equal;
158 > case ScanCode.BracketLeft: return KeyCode.BracketLeft;
159 > case ScanCode.BracketRight: return KeyCode.BracketRight;
160 > case ScanCode.Backslash: return KeyCode.Backslash;
161 > case ScanCode.IntlHash: return KeyCode.Unknown; // missing
162 > case ScanCode.Semicolon: return KeyCode.Semicolon;
163 > case ScanCode.Quote: return KeyCode.Quote;
164 > case ScanCode.Backquote: return KeyCode.Backquote;
165 > case ScanCode.Comma: return KeyCode.Comma;
166 > case ScanCode.Period: return KeyCode.Period;
167 > case ScanCode.Slash: return KeyCode.Slash;
168 > case ScanCode.IntlBackslash: return KeyCode.IntlBackslash;
169 > }
170 return KeyCode.Unknown;
173 > private static _toKeyCodeChord(chord: Chord | null): KeyCodeChord | null {
174 > if (!chord) { usLayoutResolvedKeybinding.ts ×5
175 return null;
176 }
177 > if (chord instanceof KeyCodeChord) { usLayoutResolvedKeybinding.ts ×5
178 > return chord; usLayoutResolvedKeybinding.ts ×1
179 > }
180 > const keyCode = this._scanCodeToKeyCode(chord.scanCode); usLayoutResolvedKeybinding.ts ×5
181 > if (keyCode === KeyCode.Unknown) {
182 return null;
183 }
184 > return new KeyCodeChord(chord.ctrlKey, chord.shiftKey, chord.altKey, chord.metaKey, keyCode); usLayoutResolvedKeybinding.ts ×5
187 > public static resolveKeybinding(keybinding: Keybinding, os: OperatingSystem): USLayoutResolvedKeybinding[] {
188 > const chords: KeyCodeChord[] = toEmptyArrayIfContainsNull(keybinding.chords.map(chord => this._toKeyCodeChord(chord))); usLayoutResolvedKeybinding.ts ×5
189 > if (chords.length > 0) {
190 > return [new USLayoutResolvedKeybinding(chords, os)];
191 > }
192 return [];