Skip to content

Commit d96141b

Browse files
authored
add functionality to hide open context menu (microsoft#64099)
* add functionality to hide open context menu fix toggling of ... menu on windows fix toggling of global activity bar menu on windows fix position of global activity bar menu on windows fixes microsoft#62413 fixes microsoft#61766 * addressing feedback * linting error * updating to eat mouse click to dismiss menu * remove native context menu changes as unnecessary * use an invisible div to block mouse * move logic into context menu handler * sanitize SNAP variables * rename update.channel to update.mode fixes microsoft#67407 * dervie status background from editor widget background
1 parent 2ff5d6b commit d96141b

4 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/vs/platform/contextview/browser/contextMenuHandler.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@
66
.context-view .monaco-menu {
77
min-width: 130px;
88
}
9+
10+
.context-view-block {
11+
position: fixed;
12+
left:0;
13+
top:0;
14+
z-index: -1;
15+
width: 100%;
16+
height: 100%;
17+
}

src/vs/platform/contextview/browser/contextMenuHandler.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
1616
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1717
import { IThemeService } from 'vs/platform/theme/common/themeService';
1818
import { IContextMenuDelegate } from 'vs/base/browser/contextmenu';
19-
import { addDisposableListener, EventType } from 'vs/base/browser/dom';
19+
import { addDisposableListener, EventType, $ } from 'vs/base/browser/dom';
2020
import { attachMenuStyler } from 'vs/platform/theme/common/styler';
2121
import { domEvent } from 'vs/base/browser/event';
2222

@@ -25,6 +25,7 @@ export class ContextMenuHandler {
2525
private elementDisposable: IDisposable;
2626
private menuContainerElement: HTMLElement | null;
2727
private focusToReturn: HTMLElement;
28+
private block: HTMLElement | null;
2829

2930
constructor(
3031
element: HTMLElement,
@@ -73,12 +74,14 @@ export class ContextMenuHandler {
7374
container.className += ' ' + className;
7475
}
7576

77+
// Render invisible div to block mouse interaction in the rest of the UI
78+
this.block = container.appendChild($('.context-view-block'));
79+
7680
const menuDisposables: IDisposable[] = [];
7781

7882
const actionRunner = delegate.actionRunner || new ActionRunner();
7983
actionRunner.onDidBeforeRun(this.onActionRun, this, menuDisposables);
8084
actionRunner.onDidRun(this.onDidActionRun, this, menuDisposables);
81-
8285
menu = new Menu(container, actions, {
8386
actionItemProvider: delegate.getActionItem,
8487
context: delegate.getActionsContext ? delegate.getActionsContext() : null,
@@ -106,6 +109,11 @@ export class ContextMenuHandler {
106109
delegate.onHide(!!didCancel);
107110
}
108111

112+
if (this.block) {
113+
this.block.remove();
114+
this.block = null;
115+
}
116+
109117
if (this.focusToReturn) {
110118
this.focusToReturn.focus();
111119
}

src/vs/workbench/browser/parts/activitybar/activitybarActions.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'vs/css!./media/activityaction';
77
import * as nls from 'vs/nls';
88
import * as DOM from 'vs/base/browser/dom';
99
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
10-
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
1110
import { EventType as TouchEventType, GestureEvent } from 'vs/base/browser/touch';
1211
import { Action } from 'vs/base/common/actions';
1312
import { KeyCode } from 'vs/base/common/keyCodes';
@@ -130,32 +129,29 @@ export class GlobalActivityActionItem extends ActivityActionItem {
130129

131130
this._register(DOM.addDisposableListener(this.container, DOM.EventType.MOUSE_DOWN, (e: MouseEvent) => {
132131
DOM.EventHelper.stop(e, true);
133-
134-
const event = new StandardMouseEvent(e);
135-
this.showContextMenu({ x: event.posx, y: event.posy });
132+
this.showContextMenu();
136133
}));
137134

138135
this._register(DOM.addDisposableListener(this.container, DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
139136
let event = new StandardKeyboardEvent(e);
140137
if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
141138
DOM.EventHelper.stop(e, true);
142-
143-
this.showContextMenu(this.container);
139+
this.showContextMenu();
144140
}
145141
}));
146142

147143
this._register(DOM.addDisposableListener(this.container, TouchEventType.Tap, (e: GestureEvent) => {
148144
DOM.EventHelper.stop(e, true);
149-
150-
const event = new StandardMouseEvent(e);
151-
this.showContextMenu({ x: event.posx, y: event.posy });
145+
this.showContextMenu();
152146
}));
153147
}
154148

155-
private showContextMenu(location: HTMLElement | { x: number, y: number }): void {
149+
private showContextMenu(): void {
156150
const globalAction = this._action as GlobalActivityAction;
157151
const activity = globalAction.activity as IGlobalActivity;
158152
const actions = activity.getActions();
153+
const containerPosition = DOM.getDomNodePagePosition(this.container);
154+
const location = { x: containerPosition.left + containerPosition.width / 2, y: containerPosition.top };
159155

160156
this.contextMenuService.showContextMenu({
161157
getAnchor: () => location,

src/vs/workbench/browser/parts/titlebar/media/titlebarpart.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
width: 35px;
7979
height: 100%;
8080
position: relative;
81-
z-index: 99;
81+
z-index: 3000;
8282
background-image: url('code-icon.svg');
8383
background-repeat: no-repeat;
8484
background-position: center center;
@@ -96,7 +96,7 @@
9696
flex-shrink: 0;
9797
text-align: center;
9898
position: relative;
99-
z-index: 99;
99+
z-index: 3000;
100100
-webkit-app-region: no-drag;
101101
height: 100%;
102102
width: 138px;

0 commit comments

Comments
 (0)