Skip to content
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

Conversation

kenneth-marut-work
Copy link
Contributor

@kenneth-marut-work kenneth-marut-work commented May 4, 2020

Signed-off-by: Kenneth Marut [email protected]
Signed-off-by: Colin Grant [email protected]

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 identical MouseEvent check as in:

const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor;

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 the electron-menu-context-renderer.ts

How to test

  1. Pull latest changes from Added Preferences UI widget #7105, build, and run in Electron
  2. Open new preferences UI with multiroot workspace
  3. Click on gear-icon and/or folder scope tab in preferences UI, observe bad behavior of context menu
  4. Pull changes from this PR, and rebuild in Electron
  5. Relaunch and run steps 2-3
  6. Observe context menu behaior

Review checklist

Reminder for reviewers

Signed-off-by: Kenneth Marut <[email protected]>
Signed-off-by: Colin Grant <[email protected]>
@vince-fugnitto vince-fugnitto added electron issues related to the electron target menus issues related to the menu labels May 4, 2020
Copy link
Member

@vince-fugnitto vince-fugnitto left a 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:

Screen Shot 2020-05-04 at 12 05 30 PM

After:

Screen Shot 2020-05-04 at 12 14 24 PM

@akosyakov akosyakov requested a review from kittaakos May 5, 2020 06:18
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) });
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Contributor Author

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):

image

Copy link
Contributor

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.

@kittaakos
Copy link
Contributor

@akosyakov, do you have any remarks on this PR? Otherwise, I'm going to merge it.
The electron guys have completely rewritten the rpc-server, I think this x, y rounding becomes obsolete once we bump up the electron version:

@kittaakos kittaakos merged commit fc95a75 into eclipse-theia:master May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electron issues related to the electron target menus issues related to the menu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Electron ContextMenuRenderer does not use passed-in anchor values
4 participants