From a3d96f1dae2d2c0720dc770f19206d56ef138780 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Sun, 20 Jun 2021 02:05:31 -0700 Subject: [PATCH] Reduce the greediness of keyboard input redirection Part of #124 --- client/web/src/components/panels/Document.vue | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/client/web/src/components/panels/Document.vue b/client/web/src/components/panels/Document.vue index 6e73fe60..2663afe8 100644 --- a/client/web/src/components/panels/Document.vue +++ b/client/web/src/components/panels/Document.vue @@ -187,6 +187,21 @@ const modeMenuEntries: SectionsOfMenuListEntries = [ const wasm = import("../../../wasm/pkg"); +function redirectKeyboardEventToBackend(e: KeyboardEvent): boolean { + // Don't redirect user input from text entry into HTML elements + const target = e.target as HTMLElement; + if (target.nodeName === "INPUT" || target.nodeName === "TEXTAREA" || target.isContentEditable) return false; + + // Don't redirect a fullscreen request + if (e.key.toLowerCase() === "f11") return false; + + // Don't redirect debugging tools + if (e.key.toLowerCase() === "f12") return false; + if (e.ctrlKey && e.shiftKey && e.key.toLowerCase() === "c") return false; + + return true; +} + export default defineComponent({ methods: { async canvasMouseDown(e: MouseEvent) { @@ -202,14 +217,18 @@ export default defineComponent({ on_mouse_move(e.offsetX, e.offsetY); }, async keyDown(e: KeyboardEvent) { - e.preventDefault(); - const { on_key_down } = await wasm; - on_key_down(e.key); + if (redirectKeyboardEventToBackend(e)) { + e.preventDefault(); + const { on_key_down } = await wasm; + on_key_down(e.key); + } }, async keyUp(e: KeyboardEvent) { - e.preventDefault(); - const { on_key_up } = await wasm; - on_key_up(e.key); + if (redirectKeyboardEventToBackend(e)) { + e.preventDefault(); + const { on_key_up } = await wasm; + on_key_up(e.key); + } }, async selectTool(toolName: string) { const { select_tool } = await wasm;