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

[keyboard] shortcuts trigger default actions second time #269

Open
Ehesp opened this issue Dec 8, 2022 · 3 comments
Open

[keyboard] shortcuts trigger default actions second time #269

Ehesp opened this issue Dec 8, 2022 · 3 comments

Comments

@Ehesp
Copy link

Ehesp commented Dec 8, 2022

Hey,

When I setup the following shortcut (on Mac):

createShortcut(['Meta', 'P'], () => {
    console.log('Pressed Meta + P');
});

Pressing this combo works fine, however if I fully let go, and press it again the native browser "Print" dialog will popup. I close it, press the combo again and it works fine, press again and the dialog opens (and so on...).

I've tried with requireReset on both true and false but the behaviour is the same.

This behaviour is the same on "Meta + S" too.

@thetarnav
Copy link
Member

This is interesting.
Preventing the default behavior for Control + P on Windows works as expected, but for Meta + P the native behavior is executed anyway. Not sure if events associated with Meta key cannot be prevented or what's the issue. Needs more investigating.

@Ehesp
Copy link
Author

Ehesp commented Dec 8, 2022

So for a bit more context, my current (slimmed) logic looks like this:

const isMac = navigator.platform.toLowerCase().indexOf('mac') > -1;

window.addEventListener('keydown', shortcut);

function shortcut(event: KeyboardEvent): void {
    if (isMac && e.metaKey && e.key === 'p') {
      event.preventDefault();
      // do something
    }
}

I can mash Cmd + P as much as I want and the print dialog doesn't show (this is in use here: https://zapp.run/edit/dart) - it'll trigger the command palette. I implemented the logic above to trigger the palette but yeah, it worked but then showed the print dialog the second time, so it should be possible to prevent it.

@sotasan
Copy link

sotasan commented Apr 10, 2024

Any progress so far?

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

No branches or pull requests

3 participants