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