Path: blob/main/src/vs/workbench/contrib/accessibility/browser/accessibleViewKeybindingResolver.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 { MarkdownString } from '../../../../base/common/htmlContent.js';6import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';7import { IPickerQuickAccessItem } from '../../../../platform/quickinput/browser/pickerQuickAccess.js';89export function resolveContentAndKeybindingItems(keybindingService: IKeybindingService, value?: string): { content: MarkdownString; configureKeybindingItems: IPickerQuickAccessItem[] | undefined; configuredKeybindingItems: IPickerQuickAccessItem[] | undefined } | undefined {10if (!value) {11return;12}13const configureKeybindingItems: IPickerQuickAccessItem[] = [];14const configuredKeybindingItems: IPickerQuickAccessItem[] = [];15const matches = value.matchAll(/(\<keybinding:(?<commandId>[^\<]*)\>)/gm);16for (const match of [...matches]) {17const commandId = match?.groups?.commandId;18let kbLabel;19if (match?.length && commandId) {20const keybinding = keybindingService.lookupKeybinding(commandId)?.getAriaLabel();21if (!keybinding) {22kbLabel = ` (unassigned keybinding)`;23configureKeybindingItems.push({24label: commandId,25id: commandId26});27} else {28kbLabel = ' (' + keybinding + ')';29configuredKeybindingItems.push({30label: commandId,31id: commandId32});33}34value = value.replace(match[0], kbLabel);35}36}37const content = new MarkdownString(value);38content.isTrusted = true;39return { content, configureKeybindingItems: configureKeybindingItems.length ? configureKeybindingItems : undefined, configuredKeybindingItems: configuredKeybindingItems.length ? configuredKeybindingItems : undefined };40}41424344