UNPKG

@sussudio/platform

Version:

Internal APIs for VS Code's service injection the base services.

75 lines (74 loc) 2.47 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { illegalArgument } from '@sussudio/base/common/errors.mjs'; import { AriaLabelProvider, ElectronAcceleratorLabelProvider, UILabelProvider, UserSettingsLabelProvider, } from '@sussudio/base/common/keybindingLabels.mjs'; import { ResolvedKeybinding, ResolvedChord } from '@sussudio/base/common/keybindings.mjs'; export class BaseResolvedKeybinding extends ResolvedKeybinding { _os; _chords; constructor(os, chords) { super(); if (chords.length === 0) { throw illegalArgument(`chords`); } this._os = os; this._chords = chords; } getLabel() { return UILabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getLabel(keybinding)); } getAriaLabel() { return AriaLabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getAriaLabel(keybinding)); } getElectronAccelerator() { if (this._chords.length > 1) { // [Electron Accelerators] Electron cannot handle chords return null; } if (this._chords[0].isDuplicateModifierCase()) { // [Electron Accelerators] Electron cannot handle modifier only keybindings // e.g. "shift shift" return null; } return ElectronAcceleratorLabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getElectronAccelerator(keybinding), ); } getUserSettingsLabel() { return UserSettingsLabelProvider.toLabel(this._os, this._chords, (keybinding) => this._getUserSettingsLabel(keybinding), ); } isWYSIWYG() { return this._chords.every((keybinding) => this._isWYSIWYG(keybinding)); } hasMultipleChords() { return this._chords.length > 1; } getChords() { return this._chords.map((keybinding) => this._getChord(keybinding)); } _getChord(keybinding) { return new ResolvedChord( keybinding.ctrlKey, keybinding.shiftKey, keybinding.altKey, keybinding.metaKey, this._getLabel(keybinding), this._getAriaLabel(keybinding), ); } getDispatchChords() { return this._chords.map((keybinding) => this._getChordDispatch(keybinding)); } getSingleModifierDispatchChords() { return this._chords.map((keybinding) => this._getSingleModifierChordDispatch(keybinding)); } }