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

Undo/Redo/Cut/Copy/Paste & more Not work using Menubar in Windows #18745

Closed
3 tasks done
damianaiamad opened this issue Jun 12, 2019 · 16 comments · Fixed by #19657
Closed
3 tasks done

Undo/Redo/Cut/Copy/Paste & more Not work using Menubar in Windows #18745

damianaiamad opened this issue Jun 12, 2019 · 16 comments · Fixed by #19657

Comments

@damianaiamad
Copy link

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 5.0.3
  • Operating System:
    • Windows 10 (1809)
  • Last Known Working Electron version:
    • 4.2.4

Expected Behavior

Selecting Undo/Redo/Cut/Copy/Paste/ZoomIn/ZoomOut/ResetZoom from menu bar with mouse performs those various functions.

Actual Behavior

Selecting these options from the menubar using the mouse seems to have no effect.
Using keyboard shortcuts does work ok.

Both mouse & keyboard works ok for all functions in MacOS 10.14.5.

To Reproduce

https://github.com/electron/fiddle/releases/tag/v0.8.1
Download and run, then try Edit and View menus.
This uses 5.0.1

I have same problem in my own app using 5.0.3. Problem eliminated by downgrading to 4.2.4.

Additional Information

My app uses standard MenuItem roles:

        { role: 'resetzoom' },
        { role: 'zoomin' },
        { role: 'zoomout' },

Electron Fiddle does the same:
https://github.com/electron/fiddle/blob/88ce4a76e97c4c93821306b59b3de9a147378058/src/main/menu.ts

     item.submenu.push({ type: 'separator' }, { role: 'resetzoom' }, { role: 'zoomin' }, { role: 'zoomout' }); // Add zooming actions
@codebytere
Copy link
Member

cc @felixrieseberg, perhaps this is a fiddle issue?

@damianaiamad
Copy link
Author

My app has the same problems, so I don't think it's just a fiddle problem.

Also, these "role" based menu behaviours are provided by Electron, not by application code.

@damianaiamad
Copy link
Author

I did some more investigation and can reproduce all problems with Electron API Demo.
https://github.com/electron/electron-api-demos

Current version uses Electron@4, so upgrade to Electron@5 as follows:

To Reproduce

$ git clone https://github.com/electron/electron-api-demos
$ cd electron-api-demos

Edit package.json to update electron version
"electron": "^5",

$ npm install
$ npm start

In the app go to System > Copy & paste from the clipboard

Use the provided text field to test: Undo/Redo/Cut/Copy/Paste/SelectAll

Observations

In Electron@5, when click on menubar, keyboard focus disappears from text field, doesn't work.
In Electron@4, when click on menubar keyboard focus remains in text field, works!

But this doesn't explain failure of ZoomIn/ZoomOut/ResetZoom, as follows.

** To Reproduce **

API Demo doesn't include zoom function so add.
Edit main-process/menus/application-menu.js

Add to any menu:
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },

Observations

In Electron@5, Zoom functions don't work from menubar with mouse, but work fine using keyboard shortcuts.
In Electron@4, all works ok mouse and keyboard.

@vladimiry
Copy link

vladimiry commented Jun 18, 2019

Is not this the same as #15219? Looks like it's not but might be related.

@nicodorn
Copy link

It seems to be the same as #18518 and it's not confined to Windows. I experienced the same issue running Linux. As far as I can see, there is a change in the behaviour of the menu that seems to steel the focus from the WebView. In consequence the actions have no effect.

See my comment for a workaround (which only applies under certain circumstances). Clearly a regression to 4.x.

@javan
Copy link
Contributor

javan commented Aug 1, 2019

I can confirm that the following roles do not work on Windows with Electron v5.0.8 and v6.0.0:

  • undo
  • redo
  • cut
  • copy
  • paste
  • pasteAndMatchStyle
  • selectAll
  • delete
  • resetZoom
  • zoomIn
  • zoomOut

Here's a fiddle gist: https://gist.github.com/javan/69c1075d389acd5a3437c6459e4c6a6d

The underlying issue may be the window losing focus (as noted in #18518), which appears to happen when you interact with the menu.

Note how the window blurs when clicking the menu 👎

windows-menu

This doesn't happen with earlier (<= v4.2.8) Electron versions, the window remains focused 👍

windows-menu-v4

It also doesn't happen on macOS with any Electron version, the window remains focused 👍

macos-menu

@javan
Copy link
Contributor

javan commented Aug 1, 2019

perhaps this is a fiddle issue?

To clarify, I only used a fiddle URL above because it's the easiest way to share an app that reproduces the issue. The issue itself is not related to fiddle.

@erickzhao
Copy link
Member

erickzhao commented Aug 2, 2019

Can confirm that this is occurring for me on Ubuntu 19.04 as well. Investigating. 🕵️‍♂️

Update
Seems like with both Windows and Linux, this is the behavior between versions with @javan's Fiddle repro:

  • v4.2.8 (Chromium 69.0.3497.128): Works as intended.
  • v5.0.0-nightly.20190107 (Chromium 70.0.3538.110): Unfocuses and then crashes.
  • v5.0.0-beta-5 (Chromium 73.0.3683.61): As reported.

Update
After digging into the commit history, it seems like this problem started happening after #15302. Will investigate further into a fix.

@bpasero
Copy link
Contributor

bpasero commented Aug 7, 2019

Just to confirm: When I open any menu on Linux (with Electron 6) and hit ESC to close it, focus does not return to the input field. So this is a general issue for menus, not just Undo/Redo etc.

@sofianguy sofianguy moved this from Unsorted Issues to Fixed for Next Release in 5.0.x Aug 12, 2019
@javan
Copy link
Contributor

javan commented Aug 20, 2019

This is still an issue on Windows with Electron v5.0.10 and v6.0.3 which both include #19657 (the fix). Reproducible with the same fiddle I shared above.

v5.0.10

windows-menu-roles

v6.0.3

windows-menu-roles

@sofianguy sofianguy moved this from Fixed for Next Release to Fixed in 5.0.10 in 5.0.x Aug 20, 2019
@javan
Copy link
Contributor

javan commented Aug 20, 2019

@sofianguy, ⇡ ⇡ ⇡ this wasn't actually Fixed in 5.0.10 or 6.0.3 and should be reopened (see my last comment above)

@miniak miniak reopened this Aug 20, 2019
@javan
Copy link
Contributor

javan commented Aug 27, 2019

I'm working around this issue on Windows by implementing the problematic menu roles manually. Here's a simplified version (available as a fiddle gist too):

const isWindows = process.platform == "win32"

const template = [
  {
    label: "Edit",
    submenu: isWindows ? [
      { label: "Undo",  click: focusAndPerform("undo"),  accelerator: "Ctrl+Z"       },
      { label: "Redo",  click: focusAndPerform("redo"),  accelerator: "Ctrl+Shift+Z" },
      { label: "Cut",   click: focusAndPerform("cut"),   accelerator: "Ctrl+X"       },
      { label: "Copy",  click: focusAndPerform("copy"),  accelerator: "Ctrl+C"       },
      { label: "Paste", click: focusAndPerform("paste"), accelerator: "Ctrl+V"       },
    ] : [
      { role: "undo"  },
      { role: "redo"  },
      { role: "cut"   },
      { role: "copy"  },
      { role: "paste" },
    ]
  }
]

function focusAndPerform(methodName) {
  return function(menuItem, window) {
    window.webContents.focus()
    window.webContents[methodName]()
  }
}

@erickzhao
Copy link
Member

According to @nornagon, seems like this bug was reintroduced as a side effect for another fix: #19710 (comment)

cc @javan

@codebytere
Copy link
Member

This should now be resolved by #20019.

@leonardocfor
Copy link

It is not working. undo, redo, copy, paste roles do not work using Electron ^5.0.10 on Ubuntu 18.04

@johnosbb
Copy link

Still not working on Ubuntu 16.04 LTS and Electron 12.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
5.0.x
Fixed in 5.0.10
Development

Successfully merging a pull request may close this issue.