baseResolvedKeybinding.ts ×12

Frontier kind: Code frontier

unlabeled · c_2a40b3388724

732 tests · 4549 LOC · 23 files · introduces 0 tests · 214 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges214 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
531 ranges4549 lines · 23 files · Browse complete extent
All tests (intent)
732 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.

3 files ranked by introduced lines: 214 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/keybindingLabels.ts 137 introduced LOC · 2 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- keybindingLabels.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 { Modifiers } from './keybindings.js';
7 > import { OperatingSystem } from './platform.js';
8 > import * as nls from '../../nls.js';
9 >
10 > export interface ModifierLabels {
11 > readonly ctrlKey: string;
12 > readonly shiftKey: string;
13 > readonly altKey: string;
14 > readonly metaKey: string;
15 > readonly separator: string;
16 > }
17 >
18 > export interface KeyLabelProvider<T extends Modifiers> {
19 > (keybinding: T): string | null;
20 > }
21 >
22 > export class ModifierLabelProvider {
23 >
24 > public readonly modifierLabels: ModifierLabels[];
25 >
26 > constructor(mac: ModifierLabels, windows: ModifierLabels, linux: ModifierLabels = windows) {
27 > this.modifierLabels = [null!]; // index 0 will never me accessed.
28 > this.modifierLabels[OperatingSystem.Macintosh] = mac;
29 > this.modifierLabels[OperatingSystem.Windows] = windows;
30 > this.modifierLabels[OperatingSystem.Linux] = linux;
31 > }
32 >
33 > public toLabel<T extends Modifiers>(OS: OperatingSystem, chords: readonly T[], keyLabelProvider: KeyLabelProvider<T>): string | null {
34 if (chords.length === 0) {
35 return null;
48 return result.join(' ');
49 }
51 >
52 > /**
53 > * A label provider that prints modifiers in a suitable format for displaying in the UI.
54 > */
55 > export const UILabelProvider = new ModifierLabelProvider(
56 > {
57 > ctrlKey: '\u2303',
58 > shiftKey: '⇧',
59 > altKey: '⌥',
60 > metaKey: '⌘',
61 > separator: '',
62 > },
63 > {
64 > ctrlKey: nls.localize({ key: 'ctrlKey', comment: ['This is the short form for the Control key on the keyboard'] }, "Ctrl"),
65 > shiftKey: nls.localize({ key: 'shiftKey', comment: ['This is the short form for the Shift key on the keyboard'] }, "Shift"),
66 > altKey: nls.localize({ key: 'altKey', comment: ['This is the short form for the Alt key on the keyboard'] }, "Alt"),
67 > metaKey: nls.localize({ key: 'windowsKey', comment: ['This is the short form for the Windows key on the keyboard'] }, "Windows"),
68 > separator: '+',
69 > },
70 > {
71 > ctrlKey: nls.localize({ key: 'ctrlKey', comment: ['This is the short form for the Control key on the keyboard'] }, "Ctrl"),
72 > shiftKey: nls.localize({ key: 'shiftKey', comment: ['This is the short form for the Shift key on the keyboard'] }, "Shift"),
73 > altKey: nls.localize({ key: 'altKey', comment: ['This is the short form for the Alt key on the keyboard'] }, "Alt"),
74 > metaKey: nls.localize({ key: 'superKey', comment: ['This is the short form for the Super key on the keyboard'] }, "Super"),
75 > separator: '+',
76 > }
77 > );
78 >
79 > /**
80 > * A label provider that prints modifiers in a suitable format for ARIA.
81 > */
82 > export const AriaLabelProvider = new ModifierLabelProvider(
83 > {
84 > ctrlKey: nls.localize({ key: 'ctrlKey.long', comment: ['This is the long form for the Control key on the keyboard'] }, "Control"),
85 > shiftKey: nls.localize({ key: 'shiftKey.long', comment: ['This is the long form for the Shift key on the keyboard'] }, "Shift"),
86 > altKey: nls.localize({ key: 'optKey.long', comment: ['This is the long form for the Alt/Option key on the keyboard'] }, "Option"),
87 > metaKey: nls.localize({ key: 'cmdKey.long', comment: ['This is the long form for the Command key on the keyboard'] }, "Command"),
88 > separator: '+',
89 > },
90 > {
91 > ctrlKey: nls.localize({ key: 'ctrlKey.long', comment: ['This is the long form for the Control key on the keyboard'] }, "Control"),
92 > shiftKey: nls.localize({ key: 'shiftKey.long', comment: ['This is the long form for the Shift key on the keyboard'] }, "Shift"),
93 > altKey: nls.localize({ key: 'altKey.long', comment: ['This is the long form for the Alt key on the keyboard'] }, "Alt"),
94 > metaKey: nls.localize({ key: 'windowsKey.long', comment: ['This is the long form for the Windows key on the keyboard'] }, "Windows"),
95 > separator: '+',
96 > },
97 > {
98 > ctrlKey: nls.localize({ key: 'ctrlKey.long', comment: ['This is the long form for the Control key on the keyboard'] }, "Control"),
99 > shiftKey: nls.localize({ key: 'shiftKey.long', comment: ['This is the long form for the Shift key on the keyboard'] }, "Shift"),
100 > altKey: nls.localize({ key: 'altKey.long', comment: ['This is the long form for the Alt key on the keyboard'] }, "Alt"),
101 > metaKey: nls.localize({ key: 'superKey.long', comment: ['This is the long form for the Super key on the keyboard'] }, "Super"),
102 > separator: '+',
103 > }
104 > );
105 >
106 > /**
107 > * A label provider that prints modifiers in a suitable format for Electron Accelerators.
108 > * See https://github.com/electron/electron/blob/master/docs/api/accelerator.md
109 > */
110 > export const ElectronAcceleratorLabelProvider = new ModifierLabelProvider(
111 > {
112 > ctrlKey: 'Ctrl',
113 > shiftKey: 'Shift',
114 > altKey: 'Alt',
115 > metaKey: 'Cmd',
116 > separator: '+',
117 > },
118 > {
119 > ctrlKey: 'Ctrl',
120 > shiftKey: 'Shift',
121 > altKey: 'Alt',
122 > metaKey: 'Super',
123 > separator: '+',
124 > }
125 > );
126 >
127 > /**
128 > * A label provider that prints modifiers in a suitable format for user settings.
129 > */
130 > export const UserSettingsLabelProvider = new ModifierLabelProvider(
131 > {
132 > ctrlKey: 'ctrl',
133 > shiftKey: 'shift',
134 > altKey: 'alt',
135 > metaKey: 'cmd',
136 > separator: '+',
137 > },
138 > {
139 > ctrlKey: 'ctrl',
140 > shiftKey: 'shift',
141 > altKey: 'alt',
142 > metaKey: 'win',
143 > separator: '+',
144 > },
145 > {
146 > ctrlKey: 'ctrl',
147 > shiftKey: 'shift',
148 > altKey: 'alt',
149 > metaKey: 'meta',
150 > separator: '+',
151 > }
152 > );
153 >
154 function _simpleAsString(modifiers: Modifiers, key: string, labels: ModifierLabels): string {
155 if (key === null) {
src/vs/platform/keybinding/common/baseResolvedKeybinding.ts 45 introduced LOC · 12 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- baseResolvedKeybinding.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 '../../../base/common/errors.js';
7 > import { AriaLabelProvider, ElectronAcceleratorLabelProvider, UILabelProvider, UserSettingsLabelProvider } from '../../../base/common/keybindingLabels.js';
8 > import { Chord, SingleModifierChord, ResolvedKeybinding, ResolvedChord } from '../../../base/common/keybindings.js';
9 > import { OperatingSystem } from '../../../base/common/platform.js';
10 >
11 > export abstract class BaseResolvedKeybinding<T extends Chord> extends ResolvedKeybinding {
12 >
13 > protected readonly _os: OperatingSystem;
14 > protected readonly _chords: readonly T[];
15 >
16 > constructor(os: OperatingSystem, chords: readonly T[]) {
17 super();
18 if (chords.length === 0) {
22 this._chords = chords;
23 }
25 > public getLabel(): string | null {
26 return UILabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getLabel(keybinding));
27 }
29 > public getAriaLabel(): string | null {
30 return AriaLabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getAriaLabel(keybinding));
31 }
33 > public getElectronAccelerator(): string | null {
34 if (this._chords.length > 1) {
35 // [Electron Accelerators] Electron cannot handle chords
43 return ElectronAcceleratorLabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getElectronAccelerator(keybinding));
44 }
46 > public getUserSettingsLabel(): string | null {
47 return UserSettingsLabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getUserSettingsLabel(keybinding));
48 }
50 > public isWYSIWYG(): boolean {
51 return this._chords.every((keybinding) => this._isWYSIWYG(keybinding));
52 }
54 > public hasMultipleChords(): boolean {
55 return (this._chords.length > 1);
56 }
58 > public getChords(): ResolvedChord[] {
59 return this._chords.map((keybinding) => this._getChord(keybinding));
60 }
62 > private _getChord(keybinding: T): ResolvedChord {
63 return new ResolvedChord(
64 keybinding.ctrlKey,
70 );
71 }
73 > public getDispatchChords(): (string | null)[] {
74 return this._chords.map((keybinding) => this._getChordDispatch(keybinding));
75 }
77 > public getSingleModifierDispatchChords(): (SingleModifierChord | null)[] {
78 return this._chords.map((keybinding) => this._getSingleModifierChordDispatch(keybinding));
79 }
81 > protected abstract _getLabel(keybinding: T): string | null;
82 > protected abstract _getAriaLabel(keybinding: T): string | null;
83 > protected abstract _getElectronAccelerator(keybinding: T): string | null;
84 > protected abstract _getUserSettingsLabel(keybinding: T): string | null;
85 > protected abstract _isWYSIWYG(keybinding: T): boolean;
86 > protected abstract _getChordDispatch(keybinding: T): string | null;
87 > protected abstract _getSingleModifierChordDispatch(keybinding: T): SingleModifierChord | null;
88 > }
src/vs/platform/keybinding/common/resolvedKeybindingItem.ts 32 introduced LOC · 2 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- resolvedKeybindingItem.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 { CharCode } from '../../../base/common/charCode.js';
7 > import { ResolvedKeybinding } from '../../../base/common/keybindings.js';
8 > import { ContextKeyExpression } from '../../contextkey/common/contextkey.js';
9 >
10 > export class ResolvedKeybindingItem {
11 > _resolvedKeybindingItemBrand: void = undefined;
12 >
13 > public readonly resolvedKeybinding: ResolvedKeybinding | undefined;
14 > public readonly chords: string[];
15 > public readonly bubble: boolean;
16 > public readonly command: string | null;
17 > public readonly commandArgs: any;
18 > public readonly when: ContextKeyExpression | undefined;
19 > public readonly isDefault: boolean;
20 > public readonly extensionId: string | null;
21 > public readonly isBuiltinExtension: boolean;
22 > /**
23 > * Whether this keybinding was declared as a system-wide (OS global) shortcut via
24 > * `keybindings.json`. Only ever `true` for user keybindings; defaults/extension keybindings
25 > * are always `false`.
26 > */
27 > public readonly systemWide: boolean;
28 >
29 > constructor(resolvedKeybinding: ResolvedKeybinding | undefined, command: string | null, commandArgs: any, when: ContextKeyExpression | undefined, isDefault: boolean, extensionId: string | null, isBuiltinExtension: boolean, systemWide: boolean = false) {
30 this.resolvedKeybinding = resolvedKeybinding;
31 this.chords = resolvedKeybinding ? toEmptyArrayIfContainsNull(resolvedKeybinding.getDispatchChords()) : [];
43 this.systemWide = systemWide;
44 }
46 >
47 > export function toEmptyArrayIfContainsNull<T>(arr: (T | null)[]): T[] {
48 const result: T[] = [];
49 for (let i = 0, len = arr.length; i < len; i++) {