Skip to content

Commit

Permalink
#101995 extend tooltip of menu item that defines 'alt' command (#116211)
Browse files Browse the repository at this point in the history
* do #101995 extend tooltip of menu item that defines 'alt' command

* key label is 'Option' on macOS

* use platform-specific representation of altKey

* incorporate PR feedback
  • Loading branch information
gjsjohnmurray authored Mar 10, 2021
1 parent 3ac310d commit 75da064
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/vs/platform/actions/browser/menuEntryActionViewItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { localize } from 'vs/nls';
import { ICommandAction, IMenu, IMenuActionOptions, MenuItemAction, SubmenuItemAction, Icon } from 'vs/platform/actions/common/actions';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { UILabelProvider } from 'vs/base/common/keybindingLabels';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
import { DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem';
import { isWindows, isLinux } from 'vs/base/common/platform';
import { isWindows, isLinux, OS } from 'vs/base/common/platform';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';

export function createAndFillInContextMenuActions(menu: IMenu, options: IMenuActionOptions | undefined, target: IAction[] | { primary: IAction[]; secondary: IAction[]; }, primaryGroup?: string): IDisposable {
Expand Down Expand Up @@ -187,9 +188,19 @@ export class MenuEntryActionViewItem extends ActionViewItem {
const keybindingLabel = keybinding && keybinding.getLabel();

const tooltip = this._commandAction.tooltip || this._commandAction.label;
this.label.title = keybindingLabel
let title = keybindingLabel
? localize('titleAndKb', "{0} ({1})", tooltip, keybindingLabel)
: tooltip;
if (!this._wantsAltCommand && this._action.alt) {
const altTooltip = this._action.alt.tooltip || this._action.alt.label;
const altKeybinding = this._keybindingService.lookupKeybinding(this._action.alt.id);
const altKeybindingLabel = altKeybinding && altKeybinding.getLabel();
const altTitleSection = altKeybindingLabel
? localize('titleAndKb', "{0} ({1})", altTooltip, altKeybindingLabel)
: altTooltip;
title += `\n[${UILabelProvider.modifierLabels[OS].altKey}] ${altTitleSection}`;
}
this.label.title = title;
}
}

Expand Down

0 comments on commit 75da064

Please sign in to comment.