-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
add mac compatibility mode #15
Conversation
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 |
hotkey.js
Outdated
@@ -59,14 +61,14 @@ function checkHotkey(where, code, overrides) { | |||
) | |||
} | |||
|
|||
function findHotKey(event, where, overrides) { | |||
function findHotKey(event, window, where, overrides) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use window.document
and avoid where
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done.
compat.js
Outdated
const MAC_COMPAT_KEY = Symbol('macCompat') | ||
export const MAC_COMPAT = { [MAC_COMPAT_KEY]: true } | ||
|
||
export function applyCompat(code, window, overrides, dir = 'forward') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are fighting for every bite of the library, let’s remove dir
argument if we are not using it right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like dir
as well, but we need some kind of indication of the direction we're transforming in: either one way for hotkeys (meta -> ctrl), or in the reverse direction for hints (ctrl -> meta). I removed the default parameter value though.
Glad you're back from the conf :) Updated the API. |
compat.js
Outdated
return (code, window, dir) => { | ||
if ( | ||
window.navigator.platform.indexOf('Mac') === 0 && | ||
code.indexOf('meta+ctrl') === -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use includes()
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
index.d.ts
Outdated
@@ -49,7 +55,10 @@ export type HotkeyOverride = Record<string, string> | |||
* ]) | |||
* ``` | |||
*/ | |||
export function hotkeyKeyUX(overrides?: HotkeyOverride): KeyUXModule | |||
export function hotkeyKeyUX( | |||
overrides?: HotkeyOverride, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, can be overrides
a transformer too?
hotkeyKeyUX([overrides(config), macCompact])
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mentioned that earlier: #15 (comment) :)
Since it looks like you agree, I'll go ahead and implement this.
index.js
Outdated
let realCode = code | ||
for (let i in overrides) { | ||
if (overrides[i] === code) { | ||
realCode = i | ||
break | ||
} | ||
} | ||
transformers.forEach( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s write it as:
for (let transformer of transformers) {
realCode = transform(realCode, window, 'r')
}
To avoid (x = 1)
@ai Just letting you know, this PR is not abandoned, I will have time to revisit it later this week 👍 |
d313aca
to
f27a89b
Compare
built on top of the transformers api
README.md
Outdated
|
||
### Mac Compatibility Mode | ||
|
||
It's common to use the Meta (<kbd>⌘</kbd>) modifier for hotkeys on Mac, while |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's common to use the Meta (<kbd>⌘</kbd>) modifier for hotkeys on Mac, while | |
It’s common to use the Meta (<kbd>⌘</kbd>) modifier for hotkeys on Mac, while |
README.md
Outdated
### Mac Compatibility Mode | ||
|
||
It's common to use the Meta (<kbd>⌘</kbd>) modifier for hotkeys on Mac, while | ||
Window and Linux usually favor the Ctrl key. To provide familiar experience on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Window and Linux usually favor the Ctrl key. To provide familiar experience on | |
Window and Linux usually favor the <kbd>Ctrl</kbd>. To provide familiar experience on |
README.md
Outdated
getHotKeyHint(window, 'ctrl+b', [macCompat]) | ||
``` | ||
|
||
Hotkeys pressed with the Meta modifier will work as if the Ctrl modifier was |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s use <kbd>
on every key mentioning.
The more text modifiers make reading easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks nicer for sure.
Nice. Thanks. I will release it after the shower. Do you have Twitter account to mention you? |
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 :) |
Thanks. Released in 0.7. |
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
invokesctrl+b
,meta+ctrl+b
still invokesmeta+ctrl+b
.To keep the API minimal, I'm piggybacking on top of theoverrides
object, because basically this is a special kind of an override. A special opaque objectMAC_COMPAT
is exported, which can be mixed in with the rest of the overrides.getHotKeyHint
also supports this and renders Ctrl as⌘
.I'm open to all suggestions regarding the API and the idea in general.