ai / keyux

JS library to improve keyboard UI of web apps
https://ai.github.io/keyux/
MIT License
391 stars 18 forks source link

add mac compatibility mode #15

Closed myandrienko closed 5 months ago

myandrienko commented 6 months ago

This change is potentially controversial, so consider it RFC rather than something final :)

On Mac a common modifier for hotkeys is Meta (aka Cmd, aka ), while Ctrl is usually avoided. On the other hand, it's very uncommon for the Meta key to be used for app-level hotkeys on Windows or Linux.

To provide a familiar experience for users on all platforms, I suggest the Mac compatibility mode, which treats the Meta modifier as if it is Ctrl on Macs (unless both are used). So on Mac meta+b invokes ctrl+b, meta+ctrl+b still invokes meta+ctrl+b.

To keep the API minimal, I'm piggybacking on top of the overrides object, because basically this is a special kind of an override. A special opaque object MAC_COMPAT is exported, which can be mixed in with the rest of the overrides.

import { hotkeyKeyUX, startKeyUX, MAC_COMPAT } from 'keyux'

startKeyUX(window, [
  hotkeyKeyUX({ ...MAC_COMPAT })
])

getHotKeyHint also supports this and renders Ctrl as .

I'm open to all suggestions regarding the API and the idea in general.

ai commented 6 months ago

I thought about something this as well. I think we should have it, at least as an option.

I will think about architecture after I finish my task at the conference. Around next week

myandrienko commented 6 months ago

Glad you're back from the conf :) Updated the API.

myandrienko commented 5 months ago

@ai Just letting you know, this PR is not abandoned, I will have time to revisit it later this week 👍

myandrienko commented 5 months ago

I've rebased this PR to be on top of https://github.com/ai/keyux/pull/20. Let's revisit it when (and if) https://github.com/ai/keyux/pull/20 gets merged.

ai commented 5 months ago

Nice. Thanks. I will release it after the shower.

Do you have Twitter account to mention you?

myandrienko commented 5 months ago

Thanks for reviewing so quickly! I'm not really on Twitter, but if you're comfortable doing so, you can link my Telegram channel: https://t.me/smalldogenergy - although it's fine if you won't :)

ai commented 5 months ago

Thanks. Released in 0.7.