Skip to content

Commit baaeaec

Browse files
committed
1 parent 65c331c commit baaeaec

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

src/vs/base/browser/ui/actionbar/actionViewItems.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,9 @@ export class BaseActionViewItem extends Disposable implements IActionViewItem {
137137

138138
this._register(DOM.addDisposableListener(element, DOM.EventType.CLICK, e => {
139139
DOM.EventHelper.stop(e, true);
140-
// See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Interact_with_the_clipboard
141-
// > Writing to the clipboard
142-
// > You can use the "cut" and "copy" commands without any special
143-
// permission if you are using them in a short-lived event handler
144-
// for a user action (for example, a click handler).
145-
146-
// => to get the Copy and Paste context menu actions working on Firefox,
147-
// there should be no timeout here
148-
if (this.options && this.options.isMenu) {
149-
this.onClick(e);
150-
} else {
140+
141+
// menus do not use the click event
142+
if (!(this.options && this.options.isMenu)) {
151143
platform.setImmediate(() => this.onClick(e));
152144
}
153145
}));

src/vs/base/browser/ui/menu/menu.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { isLinux, isMacintosh } from 'vs/base/common/platform';
2121
import { Codicon, registerIcon, stripCodicons } from 'vs/base/common/codicons';
2222
import { BaseActionViewItem, ActionViewItem, IActionViewItemOptions } from 'vs/base/browser/ui/actionbar/actionViewItems';
2323
import { formatRule } from 'vs/base/browser/ui/codicons/codiconStyles';
24+
import { isFirefox } from 'vs/base/browser/browser';
25+
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
2426

2527
export const MENU_MNEMONIC_REGEX = /\(&([^\s&])\)|(^|[^&])&([^\s&])/;
2628
export const MENU_ESCAPED_MNEMONIC_REGEX = /(&)?(&)([^\s&])/g;
@@ -424,9 +426,29 @@ class BaseMenuActionViewItem extends BaseActionViewItem {
424426
// add back if issues arise and link new issue
425427
EventHelper.stop(e, true);
426428

427-
// Set timout to allow context menu cancellation to trigger
428-
// otherwise the action will destroy the menu and context menu
429-
// will still trigger
429+
// See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Interact_with_the_clipboard
430+
// > Writing to the clipboard
431+
// > You can use the "cut" and "copy" commands without any special
432+
// permission if you are using them in a short-lived event handler
433+
// for a user action (for example, a click handler).
434+
435+
// => to get the Copy and Paste context menu actions working on Firefox,
436+
// there should be no timeout here
437+
if (isFirefox) {
438+
const mouseEvent = new StandardMouseEvent(e);
439+
440+
// Allowing right click to trigger the event causes the issue described below,
441+
// but since the solution below does not work in FF, we must disable right click
442+
if (mouseEvent.rightButton) {
443+
return;
444+
}
445+
446+
this.onClick(e);
447+
}
448+
449+
// In all other cases, set timout to allow context menu cancellation to trigger
450+
// otherwise the action will destroy the menu and a second context menu
451+
// will still trigger for right click.
430452
setTimeout(() => {
431453
this.onClick(e);
432454
}, 0);

0 commit comments

Comments
 (0)