Fix keys typed in text fields also triggering editor shortcuts (#4713)

This commit is contained in:
Keavon Chambers authored and GitHub committed 2026-10-15 08:29:36 +00:00
1 parent 53dcdc194a
commit e0936929da
5 files changed
+10 -7

No files matched your search

+3 -2
View File
@@ -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) {
+1 -2
View File
@@ -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;
@@ -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") {
@@ -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();
+3 -2
View File
@@ -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;