1
0
mirror of https://gitlab.com/bramw/baserow.git synced 2024-11-21 23:37:55 +00:00
bramw_baserow/web-frontend/modules/core/utils/events.js

40 lines
1.1 KiB
JavaScript

/*
This function is a helper which determines whether the pressed key
is 'not a Control Key Character'
thereby determining if the key is a 'printable character'.
Any key combination with a control or a meta key is NOT a
'printable character' thereby making it possible to use combinations
such as CTRL+C/CTRL+V.
*/
export function isPrintableUnicodeCharacterKeyPress(event) {
if (event == null || isOsSpecificModifierPressed(event)) {
return false
}
const { key } = event
const nonControlCharacterRegex = /^\P{C}$/iu
if (nonControlCharacterRegex.test(key)) {
return true
}
return false
}
/**
* This function is a helper which determines whether the pressed key
* is the CMD key on Mac or the CTRL key on Windows/Linux.
*/
export const isOsSpecificModifierPressed = (event) => {
const isMac = navigator.platform.toUpperCase().includes('MAC')
return isMac ? event.metaKey : event.ctrlKey
}
export const keyboardShortcutsToPriorityEventBus = (event, priorityBus) => {
if (
isOsSpecificModifierPressed(event) &&
event.shiftKey &&
event.key.toLowerCase() === 's'
) {
priorityBus.$emit('start-search', { event })
}
}