Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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