Skip to content

Commit

Permalink
fix(useHotKey): respect press of MacOS Cmd key as Ctrl key
Browse files Browse the repository at this point in the history
Signed-off-by: Antreesy <antreesy.web@gmail.com>
  • Loading branch information
Antreesy authored and susnux committed Aug 30, 2024
1 parent 627ffa0 commit 1062676
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/composables/useHotKey.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/composables/useHotKey/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 1062676

Please sign in to comment.