From 5e52d73b4cddca5695e113dcca472862603cbdad Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 25 Aug 2016 09:23:27 +0200 Subject: [PATCH] always listen on alt-key, show alt-command on altkey and hover, fixes #9861 --- .../actions/browser/menuItemActionItem.ts | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/vs/platform/actions/browser/menuItemActionItem.ts b/src/vs/platform/actions/browser/menuItemActionItem.ts index 5743a22846b..dd417e9a3f9 100644 --- a/src/vs/platform/actions/browser/menuItemActionItem.ts +++ b/src/vs/platform/actions/browser/menuItemActionItem.ts @@ -80,6 +80,7 @@ const _altKey = new class extends Emitter { this._subscriptions.push(domEvent(document.body, 'keydown')(e => this.fire(e.altKey))); this._subscriptions.push(domEvent(document.body, 'keyup')(e => this.fire(false))); this._subscriptions.push(domEvent(document.body, 'mouseleave')(e => this.fire(false))); + this._subscriptions.push(domEvent(document.body, 'blur')(e => this.fire(false))); } dispose() { @@ -90,7 +91,7 @@ const _altKey = new class extends Emitter { class MenuItemActionItem extends ActionItem { - private _altKeyDown: boolean = false; + private _wantsAltCommand: boolean = false; constructor( action: MenuItemAction, @@ -102,14 +103,14 @@ class MenuItemActionItem extends ActionItem { private get _command() { const {command, altCommand} = this._action; - return this._altKeyDown && altCommand || command; + return this._wantsAltCommand && altCommand || command; } onClick(event: MouseEvent): void { event.preventDefault(); event.stopPropagation(); - (this._action).run(this._altKeyDown).done(undefined, err => { + (this._action).run(this._wantsAltCommand).done(undefined, err => { this._messageService.show(Severity.Error, err); }); } @@ -117,29 +118,32 @@ class MenuItemActionItem extends ActionItem { render(container: HTMLElement): void { super.render(container); - let altSubscription: IDisposable; - let mouseOver: boolean; - this._callOnDispose.push(domEvent(container, 'mouseleave')(_ => { - mouseOver = false; - if (!this._altKeyDown) { - // stop listen on ALT - altSubscription.dispose(); - } - })); - this._callOnDispose.push(domEvent(container, 'mouseenter')(e => { - mouseOver = true; - altSubscription = _altKey.event(value => { + let mouseOver = false; + let altDown = false; - this._altKeyDown = value; + const updateAltState = () => { + const wantsAltCommand = mouseOver && altDown; + if (wantsAltCommand !== this._wantsAltCommand) { + this._wantsAltCommand = wantsAltCommand; this._updateLabel(); this._updateTooltip(); this._updateClass(); + } + }; - if (!mouseOver) { - // stop listening on ALT - altSubscription.dispose(); - } - }); + this._callOnDispose.push(_altKey.event(value => { + altDown = value; + updateAltState(); + })); + + this._callOnDispose.push(domEvent(container, 'mouseleave')(_ => { + mouseOver = false; + updateAltState(); + })); + + this._callOnDispose.push(domEvent(container, 'mouseenter')(e => { + mouseOver = true; + updateAltState(); })); } -- GitLab