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: Add support for recognizing Alt key in shortcuts (#589)

Myles Scolnickd4e0fb50b515
diff --git a/frontend/src/core/hotkeys/__tests__/shortcuts.test.ts b/frontend/src/core/hotkeys/__tests__/shortcuts.test.ts
index 41d7fcf68c..44600bdced 100644
--- a/frontend/src/core/hotkeys/__tests__/shortcuts.test.ts
+++ b/frontend/src/core/hotkeys/__tests__/shortcuts.test.ts
@@ -82,4 +82,15 @@ describe("parseShortcut", () => {
expect(parseShortcut("Shift-Enter")(event)).toBe(false);
expect(parseShortcut("Cmd-Shift-Enter")(event)).toBe(true);
});
+
+ it("should not recognize shortcuts when Alt is not part of the shortcut but is pressed", () => {
+ const event = new KeyboardEvent("keydown", {
+ key: "Enter",
+ shiftKey: true,
+ altKey: true,
+ });
+
+ expect(parseShortcut("Shift-Enter")(event)).toBe(false);
+ expect(parseShortcut("Alt-Shift-Enter")(event)).toBe(true);
+ });
});
diff --git a/frontend/src/core/hotkeys/shortcuts.ts b/frontend/src/core/hotkeys/shortcuts.ts
index e77c9c16b9..eaadcdf72b 100644
--- a/frontend/src/core/hotkeys/shortcuts.ts
+++ b/frontend/src/core/hotkeys/shortcuts.ts
@@ -35,6 +35,9 @@ export function parseShortcut(shortcut: string): (e: KeyboardEvent) => boolean {
case "Shift":
satisfied &&= e.shiftKey;
break;
+ case "Alt":
+ satisfied &&= e.altKey;
+ break;
case "Space":
satisfied &&= e.code === "Space";
break;
@@ -56,6 +59,9 @@ export function parseShortcut(shortcut: string): (e: KeyboardEvent) => boolean {
if (!keys.includes("Cmd")) {
satisfied &&= !e.metaKey;
}
+ if (!keys.includes("Alt")) {
+ satisfied &&= !e.altKey;
+ }
return satisfied;
};
}
diff --git a/frontend/src/hooks/useHotkey.ts b/frontend/src/hooks/useHotkey.ts
index f66dc48112..257bd63d9c 100644
--- a/frontend/src/hooks/useHotkey.ts
+++ b/frontend/src/hooks/useHotkey.ts
@@ -7,6 +7,7 @@ import { useEvent } from "./useEvent";
import { useSetRegisteredAction } from "../core/hotkeys/actions";
import { HOTKEYS, HotkeyAction } from "@/core/hotkeys/hotkeys";
import { Objects } from "@/utils/objects";
+import { Logger } from "@/utils/Logger";
type HotkeyHandler = () => boolean | void | undefined | Promise<void>;
@@ -58,7 +59,7 @@ export function useHotkeysOnElement<T extends HotkeyAction>(
for (const [shortcut, callback] of Objects.entries(handlers)) {
const key = HOTKEYS.getHotkey(shortcut).key;
if (parseShortcut(key)(e)) {
- console.log("Satisfied", key, e);
+ Logger.debug("Satisfied", key, e);
const response = callback();
// Prevent default if the callback does not return false
if (response !== false) {
@@ -80,6 +81,7 @@ export function useKeydownOnElement(
useEventListener(element, "keydown", (e) => {
for (const [key, callback] of Objects.entries(handlers)) {
if (parseShortcut(key)(e)) {
+ Logger.debug("Satisfied", key, e);
const response = callback();
// Prevent default if the callback does not return false
if (response !== false) {