Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 30, 2024
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
Loading