-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ElectronContextMenuRenderer to use passed in anchor XY values #7735
Fix ElectronContextMenuRenderer to use passed in anchor XY values #7735
Conversation
Signed-off-by: Kenneth Marut <kenneth.marut@ericsson.com> Signed-off-by: Colin Grant <colin.grant@ericsson.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the changes against #7105 and it works correctly for me 👍
For reference I also took some screenshots:
Before:
After:
menu.popup({}); | ||
const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor!; | ||
// x and y values must be Ints or else there is a conversion error | ||
menu.popup({ x: Math.round(x), y: Math.round(y) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kittaakos maybe you can help to test it a bit against Electron
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried it, clicked around the application: I did not notice any regression. Very nice contribution, thank you! 👍 (Note: I haven't had any issues with the context menu before either.)
@kenneth-marut-work, I do not get why you have to round the coordinates? MouseEvent.clientX
has a double floating-point value. Have you experienced any malfunction?
Even if the numbers are not integers, the MouseEvent
is part of the contextmenu event
, why do not we pass x, y
further as is? I do not see any reason for the rounding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @kittaakos, thanks for the comment. I am not sure why this is necessary either, however if the number is not rounded I receive this error when testing (this has been the case on my colleague's machine as well):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could reproduce it with this change:
diff --git a/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts b/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts
index b93ae2e67..e1a4f03b5 100644
--- a/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts
+++ b/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts
@@ -46,7 +46,7 @@ export class ElectronContextMenuRenderer extends ContextMenuRenderer {
const menu = this.menuFactory.createContextMenu(menuPath, args);
const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor!;
// x and y values must be Ints or else there is a conversion error
- menu.popup({ x: Math.round(x), y: Math.round(y) });
+ menu.popup({ x: x + 0.125, y });
// native context menu stops the event loop, so there is no keyboard events
this.context.resetAltPressed();
if (onHide) {
Uncaught Error: Could not call remote function 'anonymous'. Check that the function signature is correct. Underlying error: Error processing argument at index 1, conversion failure from 607.125
Error: Could not call remote function 'anonymous'. Check that the function signature is correct. Underlying error: Error processing argument at index 1, conversion failure from 607.125
at callFunction (/Users/akos.kitta/gi…r/rpc-server.js:258)
at /Users/akos.kitta/gi…r/rpc-server.js:409
at EventEmitter.ipcMain.on.args (/Users/akos.kitta/gi…r/rpc-server.js:273)
at EventEmitter.emit (events.js:182)
at WebContents.<anonymous> (/Users/akos.kitta/gi…web-contents.js:368)
at WebContents.emit (events.js:182)
at callFunction (/Users/akos.kitta/gi…r/rpc-server.js:258)
at /Users/akos.kitta/gi…r/rpc-server.js:409
at EventEmitter.ipcMain.on.args (/Users/akos.kitta/gi…r/rpc-server.js:273)
at EventEmitter.emit (events.js:182)
at WebContents.<anonymous> (/Users/akos.kitta/gi…web-contents.js:368)
at WebContents.emit (events.js:182)
at errors.ts:26
The error comes from electron. I am OK with the rounding.
@akosyakov, do you have any remarks on this PR? Otherwise, I'm going to merge it. |
Signed-off-by: Kenneth Marut kenneth.marut@ericsson.com
Signed-off-by: Colin Grant colin.grant@ericsson.com
What it does
Fixes: #7722
This PR addresses #7722 which was uncovered in #7105 where the ElectronContextMenuRenderer did not utilize the passed in
anchor
parameter to render the menu at a given X/Y location. This caused the gear-icon and folder-scope context menus to be rendered at the mouse location rather than the passed-in anchor location. This issue is fixed by adding an identicalMouseEvent
check as in:theia/packages/core/src/browser/menu/browser-context-menu-renderer.ts
Line 30 in cea6233
And also by rounding anchor XY values to integer forms (due to a conversion error down the line) and passing the arguments into
menu.popup({ x: Math.round(x), y: Math.round(y) });
in theelectron-menu-context-renderer.ts
How to test
Review checklist
Reminder for reviewers