Prevent default browser events from firing when using keyboard shortcuts
This commit is contained in:
parent
855c5d3ae1
commit
c05c7b5f1e
|
@ -54,7 +54,7 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleKeyAction = async (component, key, ctrlKey = false) => {
|
const handleKeyAction = async (event, component, key, ctrlKey = false) => {
|
||||||
if (!component || !key) {
|
if (!component || !key) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,9 @@
|
||||||
const handler = keyHandlers[key]
|
const handler = keyHandlers[key]
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
return false
|
return false
|
||||||
|
} else if (event) {
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
}
|
}
|
||||||
return handler(component)
|
return handler(component)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -89,14 +92,14 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Key events are always for the selected component
|
// Key events are always for the selected component
|
||||||
return handleKeyAction($selectedComponent, e.key, e.ctrlKey || e.metaKey)
|
return handleKeyAction(e, $selectedComponent, e.key, e.ctrlKey || e.metaKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleComponentMenu = async e => {
|
const handleComponentMenu = async e => {
|
||||||
// Menu events can be for any component
|
// Menu events can be for any component
|
||||||
const { id, key, ctrlKey } = e.detail
|
const { id, key, ctrlKey } = e.detail
|
||||||
const component = findComponent($selectedScreen.props, id)
|
const component = findComponent($selectedScreen.props, id)
|
||||||
return await handleKeyAction(component, key, ctrlKey)
|
return await handleKeyAction(null, component, key, ctrlKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
|
Loading…
Reference in New Issue