mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(editor): Undo keybinding changes related to window focus/blur events (#13559)
This commit is contained in:
@@ -163,30 +163,4 @@ describe('useKeybindings', () => {
|
|||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
expect(handler).toHaveBeenCalled();
|
expect(handler).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not call handler when window is blurred, until it is focused back', async () => {
|
|
||||||
const handler = vi.fn();
|
|
||||||
const keymap = ref({ a: handler });
|
|
||||||
|
|
||||||
useKeybindings(keymap);
|
|
||||||
|
|
||||||
const event = new KeyboardEvent('keydown', { key: 'a' });
|
|
||||||
document.dispatchEvent(event);
|
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalled();
|
|
||||||
|
|
||||||
const blurEvent = new Event('blur');
|
|
||||||
window.dispatchEvent(blurEvent);
|
|
||||||
|
|
||||||
document.dispatchEvent(event);
|
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledTimes(1);
|
|
||||||
|
|
||||||
const focusEvent = new Event('focus');
|
|
||||||
window.dispatchEvent(focusEvent);
|
|
||||||
|
|
||||||
document.dispatchEvent(event);
|
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledTimes(2);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useActiveElement, useEventListener } from '@vueuse/core';
|
import { useActiveElement, useEventListener } from '@vueuse/core';
|
||||||
import { useDeviceSupport } from '@n8n/composables/useDeviceSupport';
|
import { useDeviceSupport } from '@n8n/composables/useDeviceSupport';
|
||||||
import type { MaybeRef, Ref } from 'vue';
|
import type { MaybeRef, Ref } from 'vue';
|
||||||
import { computed, ref, unref } from 'vue';
|
import { computed, unref } from 'vue';
|
||||||
|
|
||||||
type KeyMap = Record<string, (event: KeyboardEvent) => void>;
|
type KeyMap = Record<string, (event: KeyboardEvent) => void>;
|
||||||
|
|
||||||
@@ -142,17 +142,5 @@ export const useKeybindings = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const unregister = ref<ReturnType<typeof useEventListener> | undefined>();
|
useEventListener(document, 'keydown', onKeyDown);
|
||||||
|
|
||||||
function registerKeybindings() {
|
|
||||||
unregister.value = useEventListener(document, 'keydown', onKeyDown);
|
|
||||||
}
|
|
||||||
|
|
||||||
function unregisterKeybindings() {
|
|
||||||
unregister.value?.();
|
|
||||||
}
|
|
||||||
|
|
||||||
registerKeybindings();
|
|
||||||
useEventListener(window, 'blur', unregisterKeybindings);
|
|
||||||
useEventListener(window, 'focus', registerKeybindings);
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user