keybindings.ts ×17

Frontier kind: Code frontier

unlabeled · c_214b983358ec

915 tests · 4321 LOC · 20 files · introduces 0 tests · 151 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges151 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
508 ranges4321 lines · 20 files · Browse complete extent
All tests (intent)
915 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 151 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/keybindings.ts 151 introduced LOC · 17 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- keybindings.ts
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 { illegalArgument } from './errors.js';
7 > import { KeyCode, ScanCode } from './keyCodes.js';
8 > import { OperatingSystem } from './platform.js';
9 >
10 > /**
11 > * Binary encoding strategy:
12 > * ```
13 > * 1111 11
14 > * 5432 1098 7654 3210
15 > * ---- CSAW KKKK KKKK
16 > * C = bit 11 = ctrlCmd flag
17 > * S = bit 10 = shift flag
18 > * A = bit 9 = alt flag
19 > * W = bit 8 = winCtrl flag
20 > * K = bits 0-7 = key code
21 > * ```
22 > */
23 > const enum BinaryKeybindingsMask {
24 > CtrlCmd = (1 << 11) >>> 0,
25 > Shift = (1 << 10) >>> 0,
26 > Alt = (1 << 9) >>> 0,
27 > WinCtrl = (1 << 8) >>> 0,
28 > KeyCode = 0x000000FF
29 > }
30 >
31 > export function decodeKeybinding(keybinding: number | number[], OS: OperatingSystem): Keybinding | null {
32 if (typeof keybinding === 'number') {
33 if (keybinding === 0) {
51 }
52 }
54 > export function createSimpleKeybinding(keybinding: number, OS: OperatingSystem): KeyCodeChord {
55
56 const ctrlCmd = (keybinding & BinaryKeybindingsMask.CtrlCmd ? true : false);
65 return new KeyCodeChord(ctrlKey, shiftKey, altKey, metaKey, keyCode);
66 }
68 > export interface Modifiers {
69 > readonly ctrlKey: boolean;
70 > readonly shiftKey: boolean;
71 > readonly altKey: boolean;
72 > readonly metaKey: boolean;
73 > }
74 >
75 > /**
76 > * Represents a chord which uses the `keyCode` field of keyboard events.
77 > * A chord is a combination of keys pressed simultaneously.
78 > */
79 > export class KeyCodeChord implements Modifiers {
80 >
81 > constructor(
82 public readonly ctrlKey: boolean,
83 public readonly shiftKey: boolean,
86 public readonly keyCode: KeyCode
87 ) { }
89 > public equals(other: Chord): boolean {
90 return (
91 other instanceof KeyCodeChord
97 );
98 }
100 > public getHashCode(): string {
101 const ctrl = this.ctrlKey ? '1' : '0';
102 const shift = this.shiftKey ? '1' : '0';
105 return `K${ctrl}${shift}${alt}${meta}${this.keyCode}`;
106 }
108 > public isModifierKey(): boolean {
109 return (
110 this.keyCode === KeyCode.Unknown
115 );
116 }
118 > public toKeybinding(): Keybinding {
119 return new Keybinding([this]);
120 }
122 > /**
123 > * Does this keybinding refer to the key code of a modifier and it also has the modifier flag?
124 > */
125 > public isDuplicateModifierCase(): boolean {
126 return (
127 (this.ctrlKey && this.keyCode === KeyCode.Ctrl)
131 );
132 }
133 > } keybindings.ts
134 >
135 > /**
136 > * Represents a chord which uses the `code` field of keyboard events.
137 > * A chord is a combination of keys pressed simultaneously.
138 > */
139 > export class ScanCodeChord implements Modifiers {
140 >
141 > constructor(
142 public readonly ctrlKey: boolean,
143 public readonly shiftKey: boolean,
146 public readonly scanCode: ScanCode
147 ) { }
149 > public equals(other: Chord): boolean {
150 return (
151 other instanceof ScanCodeChord
157 );
158 }
160 > public getHashCode(): string {
161 const ctrl = this.ctrlKey ? '1' : '0';
162 const shift = this.shiftKey ? '1' : '0';
165 return `S${ctrl}${shift}${alt}${meta}${this.scanCode}`;
166 }
168 > /**
169 > * Does this keybinding refer to the key code of a modifier and it also has the modifier flag?
170 > */
171 > public isDuplicateModifierCase(): boolean {
172 return (
173 (this.ctrlKey && (this.scanCode === ScanCode.ControlLeft || this.scanCode === ScanCode.ControlRight))
177 );
178 }
179 > } keybindings.ts
180 >
181 > export type Chord = KeyCodeChord | ScanCodeChord;
182 >
183 > /**
184 > * A keybinding is a sequence of chords.
185 > */
186 > export class Keybinding {
187 >
188 > public readonly chords: Chord[];
189 >
190 > constructor(chords: Chord[]) {
191 if (chords.length === 0) {
192 throw illegalArgument(`chords`);
194 this.chords = chords;
195 }
197 > public getHashCode(): string {
198 let result = '';
199 for (let i = 0, len = this.chords.length; i < len; i++) {
205 return result;
206 }
208 > public equals(other: Keybinding | null): boolean {
209 if (other === null) {
210 return false;
220 return true;
221 }
222 > } keybindings.ts
223 >
224 > export class ResolvedChord {
225 > constructor(
226 public readonly ctrlKey: boolean,
227 public readonly shiftKey: boolean,
231 public readonly keyAriaLabel: string | null
232 ) { }
233 > } keybindings.ts
234 >
235 > export type SingleModifierChord = 'ctrl' | 'shift' | 'alt' | 'meta';
236 >
237 > /**
238 > * A resolved keybinding. Consists of one or multiple chords.
239 > */
240 > export abstract class ResolvedKeybinding {
241 > /**
242 > * This prints the binding in a format suitable for displaying in the UI.
243 > */
244 > public abstract getLabel(): string | null;
245 > /**
246 > * This prints the binding in a format suitable for ARIA.
247 > */
248 > public abstract getAriaLabel(): string | null;
249 > /**
250 > * This prints the binding in a format suitable for electron's accelerators.
251 > * See https://github.com/electron/electron/blob/master/docs/api/accelerator.md
252 > */
253 > public abstract getElectronAccelerator(): string | null;
254 > /**
255 > * This prints the binding in a format suitable for user settings.
256 > */
257 > public abstract getUserSettingsLabel(): string | null;
258 > /**
259 > * Is the user settings label reflecting the label?
260 > */
261 > public abstract isWYSIWYG(): boolean;
262 > /**
263 > * Does the keybinding consist of more than one chord?
264 > */
265 > public abstract hasMultipleChords(): boolean;
266 > /**
267 > * Returns the chords that comprise of the keybinding.
268 > */
269 > public abstract getChords(): ResolvedChord[];
270 > /**
271 > * Returns the chords as strings useful for dispatching.
272 > * Returns null for modifier only chords.
273 > * @example keybinding "Shift" -> null
274 > * @example keybinding ("D" with shift == true) -> "shift+D"
275 > */
276 > public abstract getDispatchChords(): (string | null)[];
277 > /**
278 > * Returns the modifier only chords as strings useful for dispatching.
279 > * Returns null for chords that contain more than one modifier or a regular key.
280 > * @example keybinding "Shift" -> "shift"
281 > * @example keybinding ("D" with shift == true") -> null
282 > */
283 > public abstract getSingleModifierDispatchChords(): (SingleModifierChord | null)[];
284 > }