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

Prevent default event action #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fxha
Copy link

@fxha fxha commented Nov 12, 2019

Add support to prevent the default action when the callback returns true. E.g:

electronLocalshortcut.register(win, accelerator, () => {
  // ...
  return true // prevent default action
})

fixes #69

@ibc
Copy link

ibc commented Jul 1, 2020

Never merged, right?

@@ -132,7 +132,9 @@ const _onBeforeInput = shortcutsOfWindow => (e, input) => {
for (const {eventStamp, callback} of shortcutsOfWindow) {
if (equals(eventStamp, event)) {
debug(`eventStamp: ${eventStamp} match`);
callback();
if (callback()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why not pass e to the callback and let the downstream code preventDefault? That feels more "normal" like working with typical event handler callbacks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this from our use case and we always return true to prevent Electron from handling events (c&p from our fork). I also prefer the cleaner control flow and don't think it's necessary to pass the whole event, but on the other side, others may require the event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent default event action
3 participants