fix(defineShortcuts): bring back meta to ctrl convert on non macos platforms

Resolves #3869, resolves #3318

Co-Authored-By: Sylvain Marroufin <marroufin.sylvain@gmail.com>
This commit is contained in:
Benjamin Canac
2025-04-28 11:53:13 +02:00
parent bc0a296f9d
commit f3b8b17dc5
12 changed files with 341 additions and 331 deletions

View File

@@ -3,6 +3,7 @@
import { ref, computed, toValue } from 'vue'
import type { MaybeRef } from 'vue'
import { useEventListener, useActiveElement, useDebounceFn } from '@vueuse/core'
import { useKbd } from './useKbd'
type Handler = (e?: any) => void
@@ -66,6 +67,7 @@ export function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options: Shor
}
const debouncedClearChainedInput = useDebounceFn(clearChainedInput, options.chainDelay ?? 800)
const { macOS } = useKbd()
const activeElement = useActiveElement()
const onKeyDown = (e: KeyboardEvent) => {
@@ -178,6 +180,12 @@ export function defineShortcuts(config: MaybeRef<ShortcutsConfig>, options: Shor
}
shortcut.chained = chained
// Convert Meta to Ctrl for non-MacOS
if (!macOS.value && shortcut.metaKey && !shortcut.ctrlKey) {
shortcut.metaKey = false
shortcut.ctrlKey = true
}
// Retrieve handler function
if (typeof shortcutConfig === 'function') {
shortcut.handler = shortcutConfig

View File

@@ -14,6 +14,7 @@ export const kbdKeysMap = {
win: '⊞',
command: '⌘',
shift: '⇧',
control: '⌃',
option: '⌥',
enter: '↵',
delete: '⌦',
@@ -44,9 +45,9 @@ const _useKbd = () => {
})
onMounted(() => {
kbdKeysSpecificMap.meta = macOS.value ? kbdKeysMap.command : kbdKeysMap.win
kbdKeysSpecificMap.alt = macOS.value ? kbdKeysMap.option : 'alt'
kbdKeysSpecificMap.ctrl = macOS.value ? '⌃' : 'ctrl'
kbdKeysSpecificMap.meta = macOS.value ? kbdKeysMap.command : 'Ctrl'
kbdKeysSpecificMap.ctrl = macOS.value ? kbdKeysMap.control : 'Ctrl'
kbdKeysSpecificMap.alt = macOS.value ? kbdKeysMap.option : 'Alt'
})
function getKbdKey(value?: KbdKey | string) {