Path: blob/main/src/vs/platform/keybinding/common/resolvedKeybindingItem.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CharCode } from '../../../base/common/charCode.js';6import { ResolvedKeybinding } from '../../../base/common/keybindings.js';7import { ContextKeyExpression } from '../../contextkey/common/contextkey.js';89export class ResolvedKeybindingItem {10_resolvedKeybindingItemBrand: void = undefined;1112public readonly resolvedKeybinding: ResolvedKeybinding | undefined;13public readonly chords: string[];14public readonly bubble: boolean;15public readonly command: string | null;16public readonly commandArgs: any;17public readonly when: ContextKeyExpression | undefined;18public readonly isDefault: boolean;19public readonly extensionId: string | null;20public readonly isBuiltinExtension: boolean;2122constructor(resolvedKeybinding: ResolvedKeybinding | undefined, command: string | null, commandArgs: any, when: ContextKeyExpression | undefined, isDefault: boolean, extensionId: string | null, isBuiltinExtension: boolean) {23this.resolvedKeybinding = resolvedKeybinding;24this.chords = resolvedKeybinding ? toEmptyArrayIfContainsNull(resolvedKeybinding.getDispatchChords()) : [];25if (resolvedKeybinding && this.chords.length === 0) {26// handle possible single modifier chord keybindings27this.chords = toEmptyArrayIfContainsNull(resolvedKeybinding.getSingleModifierDispatchChords());28}29this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);30this.command = this.bubble ? command!.substr(1) : command;31this.commandArgs = commandArgs;32this.when = when;33this.isDefault = isDefault;34this.extensionId = extensionId;35this.isBuiltinExtension = isBuiltinExtension;36}37}3839export function toEmptyArrayIfContainsNull<T>(arr: (T | null)[]): T[] {40const result: T[] = [];41for (let i = 0, len = arr.length; i < len; i++) {42const element = arr[i];43if (!element) {44return [];45}46result.push(element);47}48return result;49}505152