Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: ignore keyboard events when coming from an input (#4233)

Myles Scolnickc42f190af223
diff --git a/frontend/src/components/ui/button.tsx b/frontend/src/components/ui/button.tsx
index 3462dc4886..3ce7472fda 100644
--- a/frontend/src/components/ui/button.tsx
+++ b/frontend/src/components/ui/button.tsx
@@ -6,6 +6,7 @@ import { type VariantProps, cva } from "class-variance-authority";
import { cn } from "@/utils/cn";
import { parseShortcut } from "@/core/hotkeys/shortcuts";
import { useEventListener } from "@/hooks/useEventListener";
+import { Events } from "@/utils/events";
const activeCommon = "active:shadow-xsSolid";
@@ -113,6 +114,12 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
if (!keyboardShortcut) {
return;
}
+
+ // Ignore keyboard events from input elements
+ if (Events.shouldIgnoreKeyboardEvent(e)) {
+ return;
+ }
+
if (parseShortcut(keyboardShortcut)(e)) {
e.preventDefault();
e.stopPropagation();
diff --git a/frontend/src/utils/events.ts b/frontend/src/utils/events.ts
index 3ecdeb62c7..46f79ef04c 100644
--- a/frontend/src/utils/events.ts
+++ b/frontend/src/utils/events.ts
@@ -44,4 +44,23 @@ export const Events = {
target.tagName.startsWith("MARIMO")
);
},
+
+ /**
+ * Returns true if the event should be ignored because it's coming from a
+ * form element or code editor.
+ */
+ shouldIgnoreKeyboardEvent(e: KeyboardEvent) {
+ // Check for common form elements where keyboard shortcuts should be ignored
+ return (
+ e.target instanceof HTMLInputElement ||
+ e.target instanceof HTMLTextAreaElement ||
+ e.target instanceof HTMLSelectElement ||
+ (e.target instanceof HTMLElement &&
+ (e.target.isContentEditable ||
+ e.target.tagName === "BUTTON" ||
+ e.target.closest("[role='textbox']") !== null ||
+ e.target.closest("[contenteditable='true']") !== null ||
+ e.target.closest(".cm-editor") !== null)) // Add check for CodeMirror editor
+ );
+ },
};