pulsar-edit / pulsar

A Community-led Hyper-Hackable Text Editor
https://pulsar-edit.dev
Other
3.29k stars 137 forks source link

alt-key menu bar focus interference #95

Open wlwl2 opened 2 years ago

wlwl2 commented 2 years ago

Have you checked for existing feature requests?

Summary

I'm bringing an issue that Electron had into here (for a long time) to track its development. https://github.com/electron/electron/issues/34211#issue-1234548094

I'm not sure about this but I read somewhere that Pulsar was open to allowing the menu bar to be hacked (and therefore every part of the editor)? This would then be covered when that is considered as well.

Enter your response below:

Many people are having this issue, there were about 5 or 6 issues that I saw over multiple repos Electron, Atom. These ranged from language switching issues because of this new feature, important keyboard shortcuts causing issues, and just pressing the alt-key alone causing the menu bar to be focused accidently.

Any alternatives?

VSCode has settings to adjust this, but Atom doesn't. Not sure about Pulsar. See the last comment on the issue referenced.

Other examples:

This was a new update at some point causing the problem with Electron. VSCode has settings to adjust this.

confused-Techie commented 1 year ago

Sorry there was never an original response on this issue. But thanks a ton for reporting it!

Looking at the linked issue, it seems it has never been addressed by Electron maintainers and is still open. Meaning we have only a single way to change it, (which is the same way VSCode does) and that's to not use a native title bar at all.

Which that is a whole other complication into matters, but has been discussed other places as a potential solution, so there may be a lot of validity into pursuing this more, such as #442 and #345

mauricioszabo commented 1 year ago

So, if anyone wants to implement this, here are some guidelines:

All menus are defined natively in Electron, on the Main Process, at this file: src/main-process/application-menu.js

It's called via an IPC message called 'update-application-menu', defined at line 877 of src/main-process/atom-application.js. Finally, it is exposed as an API to the renderer process at src/menu-manager.js.

So, it's not that hard to fix - you just will need to make a "pure CSS + HTML" menu, and then instead of calling the IPC message, just update the UI with the relevant "new menu". The "good news" is that the IPC message always sends the full menu - meaning that you won't need to do any "diff" or whatever other stuff, you can literally destroy and reconstruct everything, everytime, and it'll work - here's an example on how the menu structure is sent via the IPC message:

image

Hopefully that helps :)


UPDATE: remember that menus can have keystrokes, so you'll probably need to add them at the keymaps too, and remove them when the menu is invalidated.

asiloisad commented 1 year ago

the easiest workaround is set new keymap for pure alt with any random text... like:

'*':
  'alt': 'miss'

An option in setting to inject this chunk into keymap will make it easier for users