Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

screencast mode: look for commands in command registry #193797

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/vs/workbench/browser/actions/developerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/commo
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import product from 'vs/platform/product/common/product';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';

class InspectContextKeysAction extends Action2 {

Expand Down Expand Up @@ -295,16 +296,14 @@ class ToggleScreencastModeAction extends Action2 {
}

const keybinding = keybindingService.resolveKeyboardEvent(event);
const command = (this._isKbFound(shortcut) && shortcut.commandId) ? MenuRegistry.getCommand(shortcut.commandId) : null;
const commandDetails = (this._isKbFound(shortcut) && shortcut.commandId) ? this.getCommandDetails(shortcut.commandId) : undefined;

let commandAndGroupLabel = '';
let commandAndGroupLabel = commandDetails?.title;
let keyLabel: string | undefined | null = keybinding.getLabel();

if (command) {
commandAndGroupLabel = typeof command.title === 'string' ? command.title : command.title.value;

if ((options.showCommandGroups ?? false) && command.category) {
commandAndGroupLabel = `${typeof command.category === 'string' ? command.category : command.category.value}: ${commandAndGroupLabel} `;
if (commandDetails) {
if ((options.showCommandGroups ?? false) && commandDetails.category) {
commandAndGroupLabel = `${commandDetails.category}: ${commandAndGroupLabel} `;
}

if (this._isKbFound(shortcut) && shortcut.commandId) {
Expand All @@ -321,7 +320,7 @@ class ToggleScreencastModeAction extends Action2 {
append(keyboardMarker, $('span.title', {}, `${commandAndGroupLabel} `));
}

if ((options.showKeys ?? true) || (command && (options.showKeybindings ?? true))) {
if ((options.showKeys ?? true) || (commandDetails && (options.showKeybindings ?? true))) {
// Fix label for arrow keys
keyLabel = keyLabel?.replace('UpArrow', '↑')
?.replace('DownArrow', '↓')
Expand All @@ -341,6 +340,25 @@ class ToggleScreencastModeAction extends Action2 {
private _isKbFound(resolutionResult: ResolutionResult): resolutionResult is { kind: ResultKind.KbFound; commandId: string | null; commandArgs: any; isBubble: boolean } {
return resolutionResult.kind === ResultKind.KbFound;
}

private getCommandDetails(commandId: string): { title: string; category?: string } | undefined {
const fromMenuRegistry = MenuRegistry.getCommand(commandId);

if (fromMenuRegistry) {
return {
title: typeof fromMenuRegistry.title === 'string' ? fromMenuRegistry.title : fromMenuRegistry.title.value,
category: fromMenuRegistry.category ? (typeof fromMenuRegistry.category === 'string' ? fromMenuRegistry.category : fromMenuRegistry.category.value) : undefined
};
}

const fromCommandsRegistry = CommandsRegistry.getCommand(commandId);

if (fromCommandsRegistry && fromCommandsRegistry.description?.description) {
return { title: fromCommandsRegistry.description.description };
}

return undefined;
}
}

class LogStorageAction extends Action2 {
Expand Down