From e0936929da7fb063bd62e59882397b70f99208bf Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Thu, 15 Oct 2026 08:29:36 +0000 Subject: [PATCH] Fix keys typed in text fields also triggering editor shortcuts (#4713) --- frontend/src/components/panels/Layers.svelte | 5 +++-- frontend/src/components/views/Graph.svelte | 3 +-- .../src/components/widgets/inputs/MathExpressionInput.svelte | 2 +- frontend/src/components/widgets/inputs/SliderInput.svelte | 2 ++ frontend/src/utility-functions/input.ts | 5 +++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/panels/Layers.svelte b/frontend/src/components/panels/Layers.svelte index b8488e1c8a..3cd6945754 100644 --- a/frontend/src/components/panels/Layers.svelte +++ b/frontend/src/components/panels/Layers.svelte @@ -11,6 +11,7 @@ import type { PortfolioStore } from "/src/stores/portfolio"; import type { TooltipStore } from "/src/stores/tooltip"; import { pasteFile } from "/src/utility-functions/files"; + import { targetIsTextField } from "/src/utility-functions/input"; import { operatingSystem } from "/src/utility-functions/platform"; import type { EditorWrapper, LayerPanelChainInsertion, LayerPanelChainNode, LayerPanelEntry, LayerStructureEntry } from "/wrapper/pkg/graphite_wasm_wrapper"; @@ -814,8 +815,8 @@ function handleLayerPanelKeyDown(e: KeyboardEvent) { // TODO: Handle this F2 shortcut detection in the backend, not frontend, so it uses the standard key binding system - // Only handle F2 if not currently editing a layer name - if (e.key === "F2" && !layers.some((layer) => layer.editingName)) { + // Only handle F2 if not currently editing a layer name or typing in another text field + if (e.key === "F2" && !layers.some((layer) => layer.editingName) && !targetIsTextField(e.target || undefined)) { // Find the first selected layer const selectedLayer = layers.find((layer) => layer.entry.selected); if (selectedLayer) { diff --git a/frontend/src/components/views/Graph.svelte b/frontend/src/components/views/Graph.svelte index 1bc6733c6e..1706d9c98f 100644 --- a/frontend/src/components/views/Graph.svelte +++ b/frontend/src/components/views/Graph.svelte @@ -63,8 +63,7 @@ else editor.setExportName(target.index, editingNameText); } - // The name fields stop propagation of the keys they handle so the global keyboard forwarder (`shouldRedirectKeyboardEventToBackend`) doesn't also dispatch them. - // Its Escape carve-out would otherwise close the graph view, and Enter could trigger unrelated bindings. + // The name fields stop propagation of the keys they handle so no window listener also acts on them function onNameInputKeyDown(e: KeyboardEvent) { if (e.key === "Enter") commitEditingName(); else if (e.key === "Escape") editingName = undefined; diff --git a/frontend/src/components/widgets/inputs/MathExpressionInput.svelte b/frontend/src/components/widgets/inputs/MathExpressionInput.svelte index 983de162c8..e80291df1a 100644 --- a/frontend/src/components/widgets/inputs/MathExpressionInput.svelte +++ b/frontend/src/components/widgets/inputs/MathExpressionInput.svelte @@ -938,7 +938,7 @@ const asksForCompletions = (e.ctrlKey && e.key === " ") || (operatingSystem() === "Mac" && e.altKey && e.key === "Escape"); if (asksForCompletions) { e.preventDefault(); - // The editor's shortcuts hear Escape even from a text field + // A parent floating menu mustn't also close e.stopPropagation(); suggest(); } else if (e.key === "Tab") { diff --git a/frontend/src/components/widgets/inputs/SliderInput.svelte b/frontend/src/components/widgets/inputs/SliderInput.svelte index a171f3421b..150e7279d6 100644 --- a/frontend/src/components/widgets/inputs/SliderInput.svelte +++ b/frontend/src/components/widgets/inputs/SliderInput.svelte @@ -3,6 +3,7 @@ import { preventEscapeClosingParentFloatingMenu } from "/src/components/layout/FloatingMenu.svelte"; import LayoutCol from "/src/components/layout/LayoutCol.svelte"; import LayoutRow from "/src/components/layout/LayoutRow.svelte"; + import { targetIsTextField } from "/src/utility-functions/input"; import type { GradientInterpolation, GradientSample, SliderInputUpdate, SliderMarker } from "/wrapper/pkg/graphite_wasm_wrapper"; const BUTTON_LEFT = 0; @@ -361,6 +362,7 @@ function deleteShortcut(e: KeyboardEvent) { if (disabled) return; if (e.key !== "Delete" && e.key !== "Backspace") return; + if (targetIsTextField(e.target || undefined)) return; if (activeMarkerIndex === undefined) return; stopDrag(); diff --git a/frontend/src/utility-functions/input.ts b/frontend/src/utility-functions/input.ts index f90e996d09..c743e323c3 100644 --- a/frontend/src/utility-functions/input.ts +++ b/frontend/src/utility-functions/input.ts @@ -39,8 +39,9 @@ export async function shouldRedirectKeyboardEventToBackend(e: KeyboardEvent, dia // But on web, we want to not redirect paste if (import.meta.env.MODE !== "native" && key === "KeyV" && accelKey) return false; - // Don't redirect user input from text entry into HTML elements - if (targetIsTextField(e.target || undefined) && key !== "Escape" && !(accelKey && ["Enter", "NumpadEnter"].includes(key))) return false; + // Don't redirect user input from text entry into HTML elements, except the keys that end the Text tool's editing in the backend + const endsTextToolEditing = e.target === textToolInteractiveInputElement && (key === "Escape" || (accelKey && ["Enter", "NumpadEnter"].includes(key))); + if (targetIsTextField(e.target || undefined) && !endsTextToolEditing) return false; // Don't redirect if a MenuList is open if (window.document.querySelector("[data-floating-menu-content]")) return false;