fix(editor): Prevent keyboard shortcuts when ndv is open in new canvas (no-changelog) (#10601)

This commit is contained in:
Alex Grozav
2024-08-29 15:25:49 +03:00
committed by GitHub
parent 95da4d4797
commit 78f34f66c6
4 changed files with 133 additions and 24 deletions

View File

@@ -1,13 +1,21 @@
import { useActiveElement, useEventListener } from '@vueuse/core';
import { useDeviceSupport } from 'n8n-design-system';
import { computed, toValue, type MaybeRefOrGetter } from 'vue';
import type { MaybeRef } from 'vue';
import { computed, toValue, type MaybeRefOrGetter, unref } from 'vue';
type KeyMap = Record<string, (event: KeyboardEvent) => void>;
export const useKeybindings = (keymap: MaybeRefOrGetter<KeyMap>) => {
export const useKeybindings = (
keymap: MaybeRefOrGetter<KeyMap>,
options?: {
disabled: MaybeRef<boolean>;
},
) => {
const activeElement = useActiveElement();
const { isCtrlKeyPressed } = useDeviceSupport();
const isDisabled = computed(() => unref(options?.disabled));
const ignoreKeyPresses = computed(() => {
if (!activeElement.value) return false;
@@ -60,7 +68,7 @@ export const useKeybindings = (keymap: MaybeRefOrGetter<KeyMap>) => {
}
function onKeyDown(event: KeyboardEvent) {
if (ignoreKeyPresses.value) return;
if (ignoreKeyPresses.value || isDisabled.value) return;
const shortcutString = toShortcutString(event);