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

simplify screencast keyboard options #187469

Merged
merged 1 commit into from
Jul 10, 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
80 changes: 48 additions & 32 deletions src/vs/workbench/browser/actions/developerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class InspectContextKeysAction extends Action2 {
}
}

interface IScreencastKeyboardOptions {
readonly showKeys?: boolean;
readonly showCommands?: boolean;
readonly showCommandGroups?: boolean;
readonly showSingleEditorCursorMoves?: boolean;
}

class ToggleScreencastModeAction extends Action2 {

static disposable: IDisposable | undefined;
Expand Down Expand Up @@ -259,11 +266,12 @@ class ToggleScreencastModeAction extends Action2 {
return;
}

const options = configurationService.getValue<IScreencastKeyboardOptions>('screencastMode.keyboardOptions');
const event = new StandardKeyboardEvent(e);
const shortcut = keybindingService.softDispatch(event, event.target);

// Hide the single arrow key pressed
if (shortcut.kind === ResultKind.KbFound && shortcut.commandId && configurationService.getValue('screencastMode.hideSingleEditorCursorMoves') && (
if (shortcut.kind === ResultKind.KbFound && shortcut.commandId && !(options.showSingleEditorCursorMoves ?? true) && (
['cursorLeft', 'cursorRight', 'cursorUp', 'cursorDown'].includes(shortcut.commandId))
) {
return;
Expand All @@ -280,18 +288,17 @@ class ToggleScreencastModeAction extends Action2 {
length = 0;
}

const format = configurationService.getValue<'keys' | 'command' | 'commandWithGroup' | 'commandAndKeys' | 'commandWithGroupAndKeys'>('screencastMode.keyboardShortcutsFormat');
const keybinding = keybindingService.resolveKeyboardEvent(event);
const command = (this._isKbFound(shortcut) && shortcut.commandId) ? MenuRegistry.getCommand(shortcut.commandId) : null;

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

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

if ((format === 'commandWithGroup' || format === 'commandWithGroupAndKeys') && command.category) {
titleLabel = `${typeof command.category === 'string' ? command.category : command.category.value}: ${titleLabel} `;
if ((options.showCommandGroups ?? false) && command.category) {
commandAndGroupLabel = `${typeof command.category === 'string' ? command.category : command.category.value}: ${commandAndGroupLabel} `;
}

if (this._isKbFound(shortcut) && shortcut.commandId) {
Expand All @@ -304,13 +311,11 @@ class ToggleScreencastModeAction extends Action2 {
}
}

const onlyKeyboardShortcuts = configurationService.getValue('screencastMode.onlyKeyboardShortcuts');

if (format !== 'keys' && titleLabel && !onlyKeyboardShortcuts) {
append(keyboardMarker, $('span.title', {}, `${titleLabel} `));
if ((options.showCommands ?? true) && commandAndGroupLabel) {
append(keyboardMarker, $('span.title', {}, `${commandAndGroupLabel} `));
}

if (onlyKeyboardShortcuts || !titleLabel || (this._isKbFound(shortcut) && shortcut.commandId) && (format === 'keys' || format === 'commandAndKeys' || format === 'commandWithGroupAndKeys')) {
if (options.showKeys ?? true) {
// Fix label for arrow keys
keyLabel = keyLabel?.replace('UpArrow', '↑')
?.replace('DownArrow', '↓')
Expand Down Expand Up @@ -421,27 +426,38 @@ configurationRegistry.registerConfiguration({
maximum: 100,
description: localize('screencastMode.fontSize', "Controls the font size (in pixels) of the screencast mode keyboard.")
},
'screencastMode.keyboardShortcutsFormat': {
enum: ['keys', 'command', 'commandWithGroup', 'commandAndKeys', 'commandWithGroupAndKeys'],
enumDescriptions: [
localize('keyboardShortcutsFormat.keys', "Keys."),
localize('keyboardShortcutsFormat.command', "Command title."),
localize('keyboardShortcutsFormat.commandWithGroup', "Command title prefixed by its group."),
localize('keyboardShortcutsFormat.commandAndKeys', "Command title and keys."),
localize('keyboardShortcutsFormat.commandWithGroupAndKeys', "Command title and keys, with the command prefixed by its group.")
],
description: localize('screencastMode.keyboardShortcutsFormat', "Controls what is displayed in the keyboard overlay when showing shortcuts."),
default: 'commandAndKeys'
},
'screencastMode.onlyKeyboardShortcuts': {
type: 'boolean',
description: localize('screencastMode.onlyKeyboardShortcuts', "Show only keyboard shortcuts in screencast mode (do not include action names)."),
default: false
},
'screencastMode.hideSingleEditorCursorMoves': {
type: 'boolean',
description: localize('screencastMode.hideSingleEditorCursorMoves', "Hide the single editor cursor move commands in screencast mode."),
default: false
'screencastMode.keyboardOptions': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these settings need deprecation that points at the new ones?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a developer action, screencast mode, I didn't give too much thought on deprecation. Let me know if you feel strongly about it.

type: 'object',
description: localize('screencastMode.keyboardOptions.description', "Options for customizing the keyboard overlay in screencast mode."),
properties: {
'showKeys': {
type: 'boolean',
default: true,
description: localize('screencastMode.keyboardOptions.showKeys', "Show raw keys.")
},
'showCommands': {
type: 'boolean',
default: true,
description: localize('screencastMode.keyboardOptions.showCommands', "Show command names.")
},
'showCommandGroups': {
type: 'boolean',
default: false,
description: localize('screencastMode.keyboardOptions.showCommandGroups', "Show command group names, when commands are also shown.")
},
'showSingleEditorCursorMoves': {
type: 'boolean',
default: true,
description: localize('screencastMode.keyboardOptions.showSingleEditorCursorMoves', "Show single editor cursor move commands.")
}
},
default: {
'showKeys': true,
'showCommands': true,
'showCommandGroups': false,
'showSingleEditorCursorMoves': true
},
additionalProperties: false
},
'screencastMode.keyboardOverlayTimeout': {
type: 'number',
Expand Down