ENA-136 Fix context menu closing on the same right-click which opened it#2834
ENA-136 Fix context menu closing on the same right-click which opened it#2834towerofnix wants to merge 2 commits intoscratchfoundation:developfrom
Conversation
Closure Library already handles the difficult work (keeping track of coordinates). This commit changes handleContextMenu so that it accesses the same code paths as normal mouse-ups (where the fix is located in Closure) and provides a supporting override which makes right-clicks "count" as the browser action button in this context. It also provides the mouse event which was responsible for creating the menu directly to the menu, which is required for the Closure Library fix to work.
core/contextmenu.js
Outdated
| // See issue #2085. | ||
| menu.setVisible( | ||
| true, // this menu is visible (this is the default anyway) | ||
| true, // "force" the value and don't emit SHOW & AFTER_SHOW events (avoid side effects) |
There was a problem hiding this comment.
Technically this line ("force") could be false since the menu is visible by default anyway, and so its value doesn't change. It would avoid some slight overhead of re-applying certain DOM values, and would be less misleading without any SHOW/AFTER_SHOW side effects—but it necessitates familiarity/assumption that the menu starts out visible. (Obviously we can take this for granted, or else menu rendering as-is wouldn't work in the first place.)
|
NB: All pull requests are failing atm, it doesn't indicate any issues with this pull request afaik. |
|
Update from the future: Someone reported that this bug still happens in TurboWarp so my patch is probably incomplete -- I am missing something. I think the only part of this that's necessary is diff --git a/core/contextmenu.js b/core/contextmenu.js
index 65401747..13b03f4e 100644
--- a/core/contextmenu.js
+++ b/core/contextmenu.js
@@ -103,9 +103,14 @@ Blockly.ContextMenu.populate_ = function(options, rtl) {
if (option.enabled) {
goog.events.listen(
menuItem, goog.ui.Component.EventType.ACTION, option.callback);
- menuItem.handleContextMenu = function(/* e */) {
- // Right-clicking on menu option should count as a click.
- goog.events.dispatchEvent(this, goog.ui.Component.EventType.ACTION);
+ menuItem.handleMouseDown = function(e) {
+ // Menu options only respond to left clicking (browser action button).
+ // Override the event to let right clicking work too.
+ e.isMouseActionButton = function() {
+ return this.isButton(goog.events.BrowserEvent.MouseButton.LEFT) ||
+ this.isButton(goog.events.BrowserEvent.MouseButton.RIGHT);
+ };
+ goog.ui.MenuItem.base(this, 'handleMouseDown', e);
};
}
}If I remove the added setVisible call, I still can't reproduce the bug. Since the problem was (to my understanding) that the browser sends a mousedown event (which shows the menu) then a contextmenu event (which forcibly selects the hovered item), removing the contextmenu listener would fix it since the contextmenu event is now ignored. Am I missing something? When I try to compile this locally for production I get which may be related to checks failing (in TurboWarp I am fixing this bug in a different way with a really sketchy hack: TurboWarp@ad65dda) |
Someone has reported that previous fix is not good enough, so let's copy this line from scratchfoundation#2834 and see if that fixes it
|
It sounds like maybe this still needs work, and additionally needs some extensive QA testing? Our devices lean heavily towards Mac/iOS/Chromebook/Android and we're pretty lacking in Windows and especially Linux... |
|
(And, thanks for all of the work on this bug!) |
|
Thanks for the review @benjiwheeler, and thanks for the input @GarboMuffin - I've been extra busy with work lately so haven't gotten around to reviewing your feedback!
This is a simpler fix than what I have, yeah. If that's the case, I think we can avoid the error you encountered (which - you're right - is also what is erroring this build) just by using the existing I'll try that locally and see if it works (and update back here), then probably test across multiple devices (I have full access to Mac, Linux, and Windows devices). |
Update: This won't work because |
|
Alright, I've pushed an alternate fix which makes most of everything in the original PR description out of date. Please see the updated description below. Proposed ChangesRemove existing code which tacks on a unique function Rather than defining Reason for ChangesThe object of both the original code (current in LLK/scratch-blocks) and the new code (this PR) is to allow right-clicking menu items to also activate the menu item, just like left-clicking. However, the original code is "hacky" in two separate ways, both of which the new code works around.
Test coverage is same as before (the same repro case described should be used). I'll manually test this across OS and browser combinations to help with QA! |
QA OS/Browser TestingUnfortunately, I couldn't find a way to reliably reproduce the bug #2085 outside of the vertical scratch-blocks playground. Where marked, I used this playground for QA; otherwise, all QA is in a local build of scratch-gui with this version of scratch-blocks linked.
|
||||||||||||||||||||||||
Resolves
Fixes #2085.
Proposed Changes
See updated: #2834 (comment). Original below:
Reason for Changes
See updated: #2834 (comment). Original below:
Test Coverage
First I created a reliable repro case which works in
tests/vertical_playground.htmlto make testing easier:In the end I tested this manually:
We also get a free actual unit test right from Closure Library!