Skip to content

Commit

Permalink
fixes #52907
Browse files Browse the repository at this point in the history
  • Loading branch information
sbatten committed Aug 27, 2018
1 parent 9ba00ca commit 1b11d00
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/vs/base/browser/ui/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ class MenuActionItem extends BaseActionItem {
$('span.keybinding').text(this.options.keybinding).appendTo(this.$e);
}

this._register(addDisposableListener(this.element, EventType.MOUSE_UP, e => {
EventHelper.stop(e, true);
this.onClick(e);
}));

this._updateClass();
this._updateLabel();
this._updateTooltip();
Expand Down
30 changes: 28 additions & 2 deletions src/vs/workbench/browser/parts/titlebar/menubarControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class MenubarControl extends Disposable {
private _mnemonicsInUse: boolean;
private openedViaKeyboard: boolean;
private awaitingAltRelease: boolean;
private ignoreNextMouseUp: boolean;
private mnemonics: Map<KeyCode, number>;

private _onVisibilityChange: Emitter<boolean>;
Expand Down Expand Up @@ -361,6 +362,7 @@ export class MenubarControl extends Disposable {
this.focusState = MenubarState.VISIBLE;
}

this.ignoreNextMouseUp = false;
this.mnemonicsInUse = false;
this.updateMnemonicVisibility(false);
}
Expand Down Expand Up @@ -751,9 +753,33 @@ export class MenubarControl extends Disposable {
}
}));

this._register(DOM.addDisposableListener(this.customMenus[menuIndex].buttonElement, DOM.EventType.CLICK, (e) => {
this.onMenuTriggered(menuIndex, true);
this._register(DOM.addDisposableListener(this.customMenus[menuIndex].buttonElement, DOM.EventType.MOUSE_DOWN, (e) => {
if (!this.isOpen) {
// Open the menu with mouse down and ignore the following mouse up event
this.ignoreNextMouseUp = true;
this.onMenuTriggered(menuIndex, true);
} else {
this.ignoreNextMouseUp = false;
}

e.preventDefault();
e.stopPropagation();
}));

this._register(DOM.addDisposableListener(this.customMenus[menuIndex].buttonElement, DOM.EventType.MOUSE_UP, (e) => {
console.log(this.ignoreNextMouseUp);
if (!this.ignoreNextMouseUp) {
this.onMenuTriggered(menuIndex, true);
} else {
console.log('ignored the mouse up');
this.ignoreNextMouseUp = false;
}

e.preventDefault();
e.stopPropagation();
}));

this._register(DOM.addDisposableListener(this.customMenus[menuIndex].buttonElement, DOM.EventType.CLICK, (e) => {
e.preventDefault();
e.stopPropagation();
}));
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/browser/parts/titlebar/titlebarPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { isMacintosh, isWindows, isLinux } from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import { Color } from 'vs/base/common/color';
import { trim } from 'vs/base/common/strings';
import { addDisposableListener, EventType, EventHelper, Dimension } from 'vs/base/browser/dom';
import { addDisposableListener, EventType, EventHelper, Dimension, isAncestor } from 'vs/base/browser/dom';
import { MenubarControl } from 'vs/workbench/browser/parts/titlebar/menubarControl';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { template, getBaseLabel } from 'vs/base/common/labels';
Expand Down Expand Up @@ -352,7 +352,11 @@ export class TitlebarPart extends Part implements ITitleService {

// Since the title area is used to drag the window, we do not want to steal focus from the
// currently active element. So we restore focus after a timeout back to where it was.
this.titleContainer.on([EventType.MOUSE_DOWN], () => {
this.titleContainer.on([EventType.MOUSE_DOWN], (e) => {
if (e.target && isAncestor(e.target as HTMLElement, this.menubar.getHTMLElement())) {
return;
}

const active = document.activeElement;
setTimeout(() => {
if (active instanceof HTMLElement) {
Expand Down

0 comments on commit 1b11d00

Please sign in to comment.