Skip to content

Commit ee03c09

Browse files
authored
allow alt key modifiers without hovering over menu items (microsoft#184688)
1 parent 40474d7 commit ee03c09

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

src/vs/platform/actions/browser/menuEntryActionViewItem.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { $, addDisposableListener, append, asCSSUrl, EventType, ModifierKeyEmitter, prepend } from 'vs/base/browser/dom';
6+
import { $, addDisposableListener, append, asCSSUrl, EventType, IModifierKeyStatus, ModifierKeyEmitter, prepend } from 'vs/base/browser/dom';
77
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
88
import { ActionViewItem, BaseActionViewItem, SelectActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
99
import { DropdownMenuActionViewItem, IDropdownMenuActionViewItemOptions } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem';
@@ -159,36 +159,21 @@ export class MenuEntryActionViewItem extends ActionViewItem {
159159
this._updateItemClass(this._menuItemAction.item);
160160
}
161161

162-
let mouseOver = false;
163-
164-
let alternativeKeyDown = this._altKey.keyStatus.altKey || ((isWindows || isLinux) && this._altKey.keyStatus.shiftKey);
165-
166-
const updateAltState = () => {
167-
const wantsAltCommand = mouseOver && alternativeKeyDown && !!this._commandAction.alt?.enabled;
168-
if (wantsAltCommand !== this._wantsAltCommand) {
169-
this._wantsAltCommand = wantsAltCommand;
170-
this.updateLabel();
171-
this.updateTooltip();
172-
this.updateClass();
173-
}
174-
};
175-
176162
if (this._menuItemAction.alt) {
177-
this._register(this._altKey.event(value => {
178-
alternativeKeyDown = value.altKey || ((isWindows || isLinux) && value.shiftKey);
179-
updateAltState();
180-
}));
181-
}
163+
const updateAltState = (keyStatus: IModifierKeyStatus) => {
164+
const wantsAltCommand = !!this._commandAction.alt?.enabled && (keyStatus.altKey || ((isWindows || isLinux) && keyStatus.shiftKey));
182165

183-
this._register(addDisposableListener(container, 'mouseleave', _ => {
184-
mouseOver = false;
185-
updateAltState();
186-
}));
166+
if (wantsAltCommand !== this._wantsAltCommand) {
167+
this._wantsAltCommand = wantsAltCommand;
168+
this.updateLabel();
169+
this.updateTooltip();
170+
this.updateClass();
171+
}
172+
};
187173

188-
this._register(addDisposableListener(container, 'mouseenter', _ => {
189-
mouseOver = true;
190-
updateAltState();
191-
}));
174+
this._register(this._altKey.event(updateAltState));
175+
updateAltState(this._altKey.keyStatus);
176+
}
192177
}
193178

194179
protected override updateLabel(): void {

0 commit comments

Comments
 (0)