fix(useHotKey): respect press of MacOS Cmd key as Ctrl key

Signed-off-by: Antreesy <antreesy.web@gmail.com>
This commit is contained in:
Antreesy 2024-08-28 12:58:27 +02:00 коммит произвёл Ferdinand Thiessen
Родитель 627ffa0ac7
Коммит 1062676671
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 45FAE7268762B400
2 изменённых файлов: 4 добавлений и 2 удалений

Просмотреть файл

@ -21,7 +21,7 @@ where:
- `push`: whether the event should be triggered on both keydown and keyup
- `prevent`: prevents the default action of the event
- `stop`: prevents propagation of the event in the capturing and bubbling phases
- `ctrl`: whether the Ctrl key should be pressed
- `ctrl`: whether the Ctrl key should be pressed (Cmd key on MacOS)
- `alt`: whether the Alt key should be pressed
- `shift`: whether the Shift key should be pressed
- `stopCallback`: a callback to stop listening to the event

Просмотреть файл

@ -5,6 +5,7 @@
import { onKeyStroke } from '@vueuse/core'
const disableKeyboardShortcuts = window.OCP?.Accessibility?.disableKeyboardShortcuts?.()
const isMac = /mac|ipad|iphone|darwin/i.test(navigator.userAgent)
/**
* Check if event target (active element) is editable (allows input from keyboard) or NcModal is open
@ -26,7 +27,8 @@ function shouldIgnoreEvent(event) {
}
const eventHandler = (callback, options) => (event) => {
if (!!options.ctrl !== event.ctrlKey) {
const ctrlKeyPressed = isMac ? event.metaKey : event.ctrlKey
if (ctrlKeyPressed !== Boolean(options.ctrl)) {
// Ctrl is required and not pressed, or the opposite
return
} else if (!!options.alt !== event.altKey) {