From 10626766712de1e5858b0f71a9babd552bfa6805 Mon Sep 17 00:00:00 2001 From: Antreesy Date: Wed, 28 Aug 2024 12:58:27 +0200 Subject: [PATCH] fix(useHotKey): respect press of MacOS Cmd key as Ctrl key Signed-off-by: Antreesy --- docs/composables/useHotKey.md | 2 +- src/composables/useHotKey/index.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/composables/useHotKey.md b/docs/composables/useHotKey.md index d50f6f6e..de089109 100644 --- a/docs/composables/useHotKey.md +++ b/docs/composables/useHotKey.md @@ -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 diff --git a/src/composables/useHotKey/index.js b/src/composables/useHotKey/index.js index 0f78ee32..b9a413ab 100644 --- a/src/composables/useHotKey/index.js +++ b/src/composables/useHotKey/index.js @@ -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) {