Add abstraction for System Modifier Key: ctrl+c on Windows equals cmd+c on macOS
vincesp opened this issue · 1 comments
vincesp commented
What problem does this feature solve?
Different operating systems use different modifier keys to denominate keyboard shortcuts.
- On Windows and Linux, the ctrl key is used. Example: ctrl+c, ctrl+a, ctrl+f etc.
- On macOS, the command key is used. Example: cmd+c, cmd+a, cmd+f
However, the command key is mapped to the .meta
system key modifier. This makes it very cumbersome to create applications that work correctly on any platform. Instead of using event modifiers, the distinction has to be made programmatically in the event callback.
@keydown.a="onAKey"
const shortcutKey = isMac ? 'metaKey' : 'ctrlKey'
function onAKey($event) {
if ($event[shortcutKey]) {
$event.preventDefault()
selectAll()
}
}
What does the proposed API look like?
Introduce a new abstract shortcut
System Modifier Key that maps to the correct key modifier on each platform.
@keydown.shortcut.a.prevent="selectAll()"