mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user