From 7b50e13ba98966c5f6616d679dc6209f1186ab6e Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sat, 24 Dec 2022 16:08:08 +0100 Subject: [PATCH] Add check: don't interpret keys if an input element is selected --- UI/Base/Hotkeys.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/UI/Base/Hotkeys.ts b/UI/Base/Hotkeys.ts index 019a57265..73093fcf6 100644 --- a/UI/Base/Hotkeys.ts +++ b/UI/Base/Hotkeys.ts @@ -5,6 +5,7 @@ import Title from "./Title" import Table from "./Table" import { UIEventSource } from "../../Logic/UIEventSource" import { VariableUiElement } from "./VariableUIElement" +import doc = Mocha.reporters.doc export default class Hotkeys { private static readonly _docs: UIEventSource< @@ -18,6 +19,11 @@ export default class Hotkeys { documentation: string }[] >([]) + + private static textElementSelected(): boolean { + console.log(document.activeElement) + return document?.activeElement?.tagName?.toLowerCase() === "input" + } public static RegisterHotkey( key: ( | { @@ -61,6 +67,10 @@ export default class Hotkeys { }) } else if (key["shift"] !== undefined) { document.addEventListener(type, function (event) { + if (Hotkeys.textElementSelected()) { + // A text element is selected, we don't do anything special + return + } if (event.shiftKey && event.key === keycode) { action() event.preventDefault() @@ -75,6 +85,10 @@ export default class Hotkeys { }) } else if (key["nomod"] !== undefined) { document.addEventListener(type, function (event) { + if (Hotkeys.textElementSelected()) { + // A text element is selected, we don't do anything special + return + } if (event.key === keycode) { action() event.preventDefault()