Skip to content

Commit 08b4bcb

Browse files
authored
Ignore mouse events when context menu is shown (microsoft#254864)
ignore mouse events when context menu is shown
1 parent 87113bc commit 08b4bcb

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/vs/editor/contrib/contextmenu/browser/contextmenu.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,6 @@ export class ContextMenuController implements IEditorContribution {
196196
return;
197197
}
198198

199-
// Disable hover
200-
const oldHoverSetting = this._editor.getOption(EditorOption.hover);
201-
this._editor.updateOptions({
202-
hover: {
203-
enabled: false
204-
}
205-
});
206-
207199
let anchor: IMouseEvent | IAnchor | null = event;
208200
if (!anchor) {
209201
// Ensure selection is visible
@@ -251,9 +243,6 @@ export class ContextMenuController implements IEditorContribution {
251243

252244
onHide: (wasCancelled: boolean) => {
253245
this._contextMenuIsBeingShownCount--;
254-
this._editor.updateOptions({
255-
hover: oldHoverSetting
256-
});
257246
}
258247
});
259248
}

src/vs/editor/contrib/hover/browser/contentHoverController.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import './hover.css';
2323
import { Emitter } from '../../../../base/common/event.js';
2424
import { isOnColorDecorator } from '../../colorPicker/browser/hoverColorPicker/hoverColorPicker.js';
2525
import { KeyCode } from '../../../../base/common/keyCodes.js';
26+
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
2627

2728
// sticky hover widget which doesn't disappear on focus out and such
2829
const _sticky = false
@@ -54,8 +55,11 @@ export class ContentHoverController extends Disposable implements IEditorContrib
5455
private _hoverSettings!: IHoverSettings;
5556
private _isMouseDown: boolean = false;
5657

58+
private _ignoreMouseEvents: boolean = false;
59+
5760
constructor(
5861
private readonly _editor: ICodeEditor,
62+
@IContextMenuService _contextMenuService: IContextMenuService,
5963
@IInstantiationService private readonly _instantiationService: IInstantiationService,
6064
@IKeybindingService private readonly _keybindingService: IKeybindingService
6165
) {
@@ -67,6 +71,13 @@ export class ContentHoverController extends Disposable implements IEditorContrib
6771
}
6872
}, 0
6973
));
74+
this._register(_contextMenuService.onDidShowContextMenu(() => {
75+
this.hideContentHover();
76+
this._ignoreMouseEvents = true;
77+
}));
78+
this._register(_contextMenuService.onDidHideContextMenu(() => {
79+
this._ignoreMouseEvents = false;
80+
}));
7081
this._hookListeners();
7182
this._register(this._editor.onDidChangeConfiguration((e: ConfigurationChangedEvent) => {
7283
if (e.hasChanged(EditorOption.hover)) {
@@ -115,12 +126,18 @@ export class ContentHoverController extends Disposable implements IEditorContrib
115126
}
116127

117128
private _onEditorScrollChanged(e: IScrollEvent): void {
129+
if (this._ignoreMouseEvents) {
130+
return;
131+
}
118132
if (e.scrollTopChanged || e.scrollLeftChanged) {
119133
this.hideContentHover();
120134
}
121135
}
122136

123137
private _onEditorMouseDown(mouseEvent: IEditorMouseEvent): void {
138+
if (this._ignoreMouseEvents) {
139+
return;
140+
}
124141
this._isMouseDown = true;
125142
const shouldKeepHoverWidgetVisible = this._shouldKeepHoverWidgetVisible(mouseEvent);
126143
if (shouldKeepHoverWidgetVisible) {
@@ -141,10 +158,16 @@ export class ContentHoverController extends Disposable implements IEditorContrib
141158
}
142159

143160
private _onEditorMouseUp(): void {
161+
if (this._ignoreMouseEvents) {
162+
return;
163+
}
144164
this._isMouseDown = false;
145165
}
146166

147167
private _onEditorMouseLeave(mouseEvent: IPartialEditorMouseEvent): void {
168+
if (this._ignoreMouseEvents) {
169+
return;
170+
}
148171
if (this.shouldKeepOpenOnEditorMouseMoveOrLeave) {
149172
return;
150173
}
@@ -198,6 +221,9 @@ export class ContentHoverController extends Disposable implements IEditorContrib
198221
}
199222

200223
private _onEditorMouseMove(mouseEvent: IEditorMouseEvent): void {
224+
if (this._ignoreMouseEvents) {
225+
return;
226+
}
201227
this._mouseMoveEvent = mouseEvent;
202228
const shouldKeepCurrentHover = this._shouldKeepCurrentHover(mouseEvent);
203229
if (shouldKeepCurrentHover) {
@@ -236,6 +262,9 @@ export class ContentHoverController extends Disposable implements IEditorContrib
236262
}
237263

238264
private _onKeyDown(e: IKeyboardEvent): void {
265+
if (this._ignoreMouseEvents) {
266+
return;
267+
}
239268
if (!this._contentWidget) {
240269
return;
241270
}

0 commit comments

Comments
 (0)