Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/keybinding/common/resolvedKeybindingItem.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 { 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
constructor(resolvedKeybinding: ResolvedKeybinding | undefined, command: string | null, commandArgs: any, when: ContextKeyExpression | undefined, isDefault: boolean, extensionId: string | null, isBuiltinExtension: boolean) {
24
this.resolvedKeybinding = resolvedKeybinding;
25
this.chords = resolvedKeybinding ? toEmptyArrayIfContainsNull(resolvedKeybinding.getDispatchChords()) : [];
26
if (resolvedKeybinding && this.chords.length === 0) {
27
// handle possible single modifier chord keybindings
28
this.chords = toEmptyArrayIfContainsNull(resolvedKeybinding.getSingleModifierDispatchChords());
29
}
30
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);
31
this.command = this.bubble ? command!.substr(1) : command;
32
this.commandArgs = commandArgs;
33
this.when = when;
34
this.isDefault = isDefault;
35
this.extensionId = extensionId;
36
this.isBuiltinExtension = isBuiltinExtension;
37
}
38
}
39
40
export function toEmptyArrayIfContainsNull<T>(arr: (T | null)[]): T[] {
41
const result: T[] = [];
42
for (let i = 0, len = arr.length; i < len; i++) {
43
const element = arr[i];
44
if (!element) {
45
return [];
46
}
47
result.push(element);
48
}
49
return result;
50
}
51
52