From 020b2d5c8e8c2121c2ec484bdeed1fb1d71efbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 7 Jul 2023 21:02:36 +0200 Subject: [PATCH] Make sure shift on Windows/Linux only works when hovering (#187308) fixes #187265 --- .../browser/menuEntryActionViewItem.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts index f2e783f211f..54400220a8e 100644 --- a/src/vs/platform/actions/browser/menuEntryActionViewItem.ts +++ b/src/vs/platform/actions/browser/menuEntryActionViewItem.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { $, addDisposableListener, append, asCSSUrl, EventType, IModifierKeyStatus, ModifierKeyEmitter, prepend } from 'vs/base/browser/dom'; +import { $, addDisposableListener, append, asCSSUrl, EventType, ModifierKeyEmitter, prepend } from 'vs/base/browser/dom'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { ActionViewItem, BaseActionViewItem, SelectActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems'; import { DropdownMenuActionViewItem, IDropdownMenuActionViewItemOptions } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem'; @@ -160,8 +160,13 @@ export class MenuEntryActionViewItem extends ActionViewItem { } if (this._menuItemAction.alt) { - const updateAltState = (keyStatus: IModifierKeyStatus) => { - const wantsAltCommand = !!this._commandAction.alt?.enabled && (keyStatus.altKey || ((isWindows || isLinux) && keyStatus.shiftKey)); + let mouseOverOnWindowsOrLinux = false; + + const updateAltState = () => { + const wantsAltCommand = !!this._menuItemAction.alt?.enabled && ( + this._altKey.keyStatus.altKey + || (this._altKey.keyStatus.shiftKey && mouseOverOnWindowsOrLinux) + ); if (wantsAltCommand !== this._wantsAltCommand) { this._wantsAltCommand = wantsAltCommand; @@ -172,7 +177,20 @@ export class MenuEntryActionViewItem extends ActionViewItem { }; this._register(this._altKey.event(updateAltState)); - updateAltState(this._altKey.keyStatus); + + if (isWindows || isLinux) { + this._register(addDisposableListener(container, 'mouseleave', _ => { + mouseOverOnWindowsOrLinux = false; + updateAltState(); + })); + + this._register(addDisposableListener(container, 'mouseenter', _ => { + mouseOverOnWindowsOrLinux = true; + updateAltState(); + })); + } + + updateAltState(); } }