vuejs / rfcs

RFCs for substantial changes / feature additions to Vue core
4.85k stars 549 forks source link

Add abstraction for System Modifier Key: ctrl+c on Windows equals cmd+c on macOS #537

Closed vincesp closed 10 months ago

vincesp commented 1 year ago

What problem does this feature solve?

Different operating systems use different modifier keys to denominate keyboard shortcuts.

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()"
yenche123 commented 11 months ago

I think we can refer to TipTap using mod instead of shortcut