Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

@ fix(keybinds): record until every key is released, not until you pause

Ruben Lütkeef4a36720164
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 48c9114b08..788a8cdde4 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -1552,6 +1552,7 @@
"recording_hint": "Halte die gewünschten Tasten (dann loslassen) — oder klick sie unten auf der Tastatur an. Wird automatisch gespeichert. Esc bricht ab.",
"record_prompt": "Drücke deine Kombination…",
"record_prompt_hint": "Jede Kombination geht — Strg, Alt, Umschalt, die Windows- oder Command-Taste und die mittlere oder seitliche Maustaste. Halte die gewünschten Tasten, dann loslassen — wird automatisch gespeichert. Esc bricht ab.",
+ "record_prompt_holding": "Weiter halten — du hast alle Zeit, um weitere Tasten dazuzunehmen. Gespeichert wird erst, wenn du jede davon losgelassen hast.",
"caution_modifier_only": "Nur Modifikatortasten: Das löst auch aus, wenn du gleichzeitig etwas anderes drückst — Strg+Windows greift also auch bei Strg+Windows+Links.",
"caution_os_shortcut": "Nichts wird abgefangen: Was diese Kombination ohnehin schon tut — ein System-Kürzel oder ein Klick auf das, worauf du zeigst — passiert weiterhin, du bekommst also beides gleichzeitig.",
"unbound": "Keine Taste zugewiesen",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index d13fc625ae..18708fbb30 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -1553,6 +1553,7 @@
"recording_hint": "Hold the keys you want (then let go), or click them on the keyboard below. It saves itself. Esc cancels.",
"record_prompt": "Press your combination…",
"record_prompt_hint": "Any combination works — Ctrl, Alt, Shift, the Windows or Command key, and the middle or side buttons of your mouse. Hold the keys you want, then let go — it saves itself. Esc cancels.",
+ "record_prompt_holding": "Keep holding — take all the time you need to add more keys. Nothing is saved until you let go of every one of them.",
"caution_modifier_only": "Modifier keys only: this also fires whenever you press something else together with them, so Ctrl+Win triggers on Ctrl+Win+Left too.",
"caution_os_shortcut": "Nothing is swallowed: whatever this combination already does — a system shortcut, or a click on whatever you are pointing at — still happens, so you get both at once.",
"unbound": "No key assigned",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index d880e349ba..d4f9c14ff6 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -1552,6 +1552,7 @@
"recording_hint": "Mantén las teclas que quieras (y suéltalas) — o haz clic en ellas en el teclado de abajo. Se guarda solo. Esc cancela.",
"record_prompt": "Pulsa tu combinación…",
"record_prompt_hint": "Vale cualquier combinación — Ctrl, Alt, Mayús, la tecla Windows o Command, y el botón central o lateral del ratón. Mantén las teclas que quieras y suéltalas: se guarda solo. Esc cancela.",
+ "record_prompt_holding": "Sigue manteniéndolas — tienes todo el tiempo para añadir más teclas. No se guarda nada hasta que sueltes todas.",
"caution_modifier_only": "Solo teclas modificadoras: también se dispara cuando pulsas otra cosa a la vez, así que Ctrl+Windows se activa también con Ctrl+Windows+Izquierda.",
"caution_os_shortcut": "No se intercepta nada: lo que esta combinación ya hace — un atajo del sistema o un clic sobre lo que estés señalando — sigue ocurriendo, así que pasan las dos cosas a la vez.",
"unbound": "Sin tecla asignada",
diff --git a/jarvis/ui/web/frontend/src/views/KeybindsPanel.test.tsx b/jarvis/ui/web/frontend/src/views/KeybindsPanel.test.tsx
index bf5d642b65..2a67e225f6 100644
--- a/jarvis/ui/web/frontend/src/views/KeybindsPanel.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/KeybindsPanel.test.tsx
@@ -156,6 +156,158 @@ describe("KeybindsPanel", () => {
expect(comboText("call")).toBe("F5+F6");
});
+ it("gives the user unlimited time to think while modifiers are held", async () => {
+ // The reported bug: "I press Ctrl+Alt, and before I can decide what the
+ // third key is, it has already saved Ctrl+Alt." Holding modifiers is how a
+ // human builds a chord, so the recorder must wait — not for longer, but for
+ // as long as the keys are down.
+ const calls = stubFetch();
+ render(<KeybindsPanel />);
+
+ await waitFor(() => expect(comboText("call")).toBe("F3+F4"));
+ fireEvent.click(screen.getByTestId("combo-field-call"));
+
+ vi.useFakeTimers();
+ try {
+ fireEvent.keyDown(window, {
+ code: "ControlLeft",
+ key: "Control",
+ ctrlKey: true,
+ });
+ fireEvent.keyDown(window, {
+ code: "AltLeft",
+ key: "Alt",
+ ctrlKey: true,
+ altKey: true,
+ });
+ // Half a minute of deciding. Nothing may leave for the backend.
+ act(() => {
+ vi.advanceTimersByTime(30_000);
+ });
+ expect(calls.some((c) => c.method === "PUT")).toBe(false);
+ // The third key still lands in the SAME gesture.
+ fireEvent.keyDown(window, {
+ code: "KeyX",
+ key: "x",
+ ctrlKey: true,
+ altKey: true,
+ });
+ } finally {
+ vi.useRealTimers();
+ }
+
+ fireEvent.keyUp(window, { code: "KeyX", key: "x", ctrlKey: true, altKey: true });
+ fireEvent.keyUp(window, { code: "AltLeft", key: "Alt", ctrlKey: true });
+ fireEvent.keyUp(window, { code: "ControlLeft", key: "Control" });
+
+ await waitFor(() =>
+ expect(
+ calls.some(
+ (c) =>
+ c.method === "PUT" &&
+ (c.body as { hotkey: string }).hotkey === "ctrl+alt+x",
+ ),
+ ).toBe(true),
+ );
+ });
+
+ it("treats a key's auto-repeat as proof it is still held", async () => {
+ // A held ordinary key reports itself as repeated keydowns. Each one has to
+ // push the swallowed-keyup rescue out of reach, or holding one key while
+ // reaching for the next commits the half-built chord.
+ const calls = stubFetch();
+ render(<KeybindsPanel />);
+
+ await waitFor(() => expect(comboText("call")).toBe("F3+F4"));
+ fireEvent.click(screen.getByTestId("combo-field-call"));
+
+ vi.useFakeTimers();
+ try {
+ fireEvent.keyDown(window, { code: "KeyX", key: "x" });
+ for (let i = 0; i < 10; i++) {
+ act(() => {
+ vi.advanceTimersByTime(500);
+ });
+ fireEvent.keyDown(window, { code: "KeyX", key: "x", repeat: true });
+ }
+ expect(calls.some((c) => c.method === "PUT")).toBe(false);
+ } finally {
+ vi.useRealTimers();
+ }
+
+ fireEvent.keyUp(window, { code: "KeyX", key: "x" });
+ await waitFor(() =>
+ expect(
+ calls.some(
+ (c) => c.method === "PUT" && (c.body as { hotkey: string }).hotkey === "x",
+ ),
+ ).toBe(true),
+ );
+ });
+
+ it("ends the gesture when the window loses focus with keys still down", async () => {
+ // Pressing the Windows key opens Start and takes focus with it, so its
+ // keyup is delivered somewhere else and never arrives. Waiting for a
+ // release that cannot come would leave the recorder armed forever.
+ const calls = stubFetch();
+ render(<KeybindsPanel />);
+
+ await waitFor(() => expect(comboText("call")).toBe("F3+F4"));
+ fireEvent.click(screen.getByTestId("combo-field-call"));
+
+ fireEvent.keyDown(window, {
+ code: "ControlLeft",
+ key: "Control",
+ ctrlKey: true,
+ });
+ fireEvent.keyDown(window, {
+ code: "MetaLeft",
+ key: "Meta",
+ ctrlKey: true,
+ metaKey: true,
+ });
+ fireEvent.blur(window);
+
+ await waitFor(() =>
+ expect(
+ calls.some(
+ (c) =>
+ c.method === "PUT" &&
+ (c.body as { hotkey: string }).hotkey === "ctrl+win",
+ ),
+ ).toBe(true),
+ );
+ });
+
+ it("recovers from a swallowed modifier keyup on the next mouse move", async () => {
+ // A mouse event carries the TRUE modifier state, so it is a free, continuous
+ // repair for a phantom held modifier — the one state no timer may resolve.
+ const calls = stubFetch();
+ render(<KeybindsPanel />);
+
+ await waitFor(() => expect(comboText("call")).toBe("F3+F4"));
+ fireEvent.click(screen.getByTestId("combo-field-call"));
+
+ fireEvent.keyDown(window, {
+ code: "ControlLeft",
+ key: "Control",
+ ctrlKey: true,
+ });
+ fireEvent.keyDown(window, { code: "KeyJ", key: "j", ctrlKey: true });
+ fireEvent.keyUp(window, { code: "KeyJ", key: "j", ctrlKey: true });
+ // Ctrl's keyup never arrives — but the mouse says it is up.
+ fireEvent.mouseMove(window, { ctrlKey: false });
+
+ await waitFor(() =>
+ expect(
+ calls.some(
+ (c) =>
+ c.method === "PUT" && (c.body as { hotkey: string }).hotkey === "ctrl+j",
+ ),
+ ).toBe(true),
+ );
+ });
+
it("lights up the on-screen keyboard live as keys are pressed", async () => {
stubFetch();
render(<KeybindsPanel />);
diff --git a/jarvis/ui/web/frontend/src/views/settings/KeybindRow.tsx b/jarvis/ui/web/frontend/src/views/settings/KeybindRow.tsx
index 85462a44c7..b07fd41597 100644
--- a/jarvis/ui/web/frontend/src/views/settings/KeybindRow.tsx
+++ b/jarvis/ui/web/frontend/src/views/settings/KeybindRow.tsx
@@ -5,6 +5,7 @@ import { Button } from "@/components/ui/button";
import {
chordToCombo,
codeToKeyToken,
+ codeToModifierToken,
composeCombo,
comboTokens,
validateCombo,
@@ -36,6 +37,22 @@ const _KB_PLATFORM = detectKeyboardPlatform();
*/
const _CLICK_SETTLE_MS = 1200;
+/**
+ * How long the recorder waits after the last key event before assuming a keyup
+ * was swallowed and committing the chord anyway.
+ *
+ * This is a RESCUE path, never the normal one. It fires only while everything
+ * still marked as held is an ordinary key — one that auto-repeats, and so
+ * re-arms this timer many times a second for as long as it is genuinely down.
+ * A held MODIFIER suppresses it outright and the recorder then waits
+ * indefinitely: holding Ctrl+Alt while deciding on the third key is how a human
+ * actually builds a chord, and committing "ctrl+alt" out from under them (the
+ * reported "it saves before I can think") is precisely what this guard exists
+ * to prevent. The gesture ends when the user lets go of everything — or when
+ * the window loses focus, which ends it whether the keys came up or not.
+ */
+const _LOST_KEYUP_MS = 900;
+
/** Pretty-print a combo string ("ctrl+right_alt+j" → "Ctrl + AltGr + J"). */
export function formatCombo(combo: string): string {
const labels: Record<string, string> = {
@@ -398,7 +415,7 @@ export function KeybindRow({
const held = new Set<string>(); // non-modifier key tokens seen this gesture
const pressed = new Set<string>(); // physical event.codes currently down
let pending: string | null = null; // fullest chord captured so far
- let idle: ReturnType<typeof setTimeout> | undefined; // fallback-commit timer
+ let idle: ReturnType<typeof setTimeout> | undefined; // rescue-commit timer
function commit() {
if (pending) {
@@ -412,16 +429,57 @@ export function KeybindRow({
}
}
+ /**
+ * Whether everything we still believe is down could plausibly be a
+ * SWALLOWED keyup rather than a key the user is deliberately holding.
+ *
+ * Modifiers are excluded because they are the one thing a person holds
+ * while thinking, and because they do not auto-repeat everywhere — a timer
+ * cannot tell "still holding Ctrl" from "Ctrl's keyup went missing", so it
+ * must not guess. Mouse buttons are excluded because their release is
+ * delivered reliably; there is nothing to rescue.
+ */
+ function staleKeysOnly() {
+ if (pressed.size === 0) return false;
+ for (const code of pressed) {
+ if (codeToModifierToken(code) !== null) return false;
+ if (code.startsWith("MouseButton")) return false;
+ }
+ return true;
+ }
+
+ // Rescue timer for keys that never deliver a keyup — function keys
+ // especially, and anything released while the window is losing focus.
+ // Without it the "commit on full release" path below would hang forever
+ // ("F5+F6 never records"). It re-arms on every key event INCLUDING
+ // auto-repeat, so a genuinely held key keeps pushing it out of reach.
+ function armRescue() {
+ if (idle) clearTimeout(idle);
+ idle = setTimeout(() => {
+ if (!staleKeysOnly()) return; // really still held → keep waiting
+ commit();
+ }, _LOST_KEYUP_MS);
+ }
+
function onKeyDown(e: KeyboardEvent) {
e.preventDefault();
e.stopPropagation();
if (e.key === "Escape") {
- if (idle) clearTimeout(idle); // cancel a pending fallback commit
+ if (idle) clearTimeout(idle); // cancel a pending rescue commit
// Undo the live preview: back to the saved value (server truth).
setCombo(currentRef.current || comboBeforeCapture.current);
setCapturing(false);
return;
}
+ // Auto-repeat carries no new information — it is the browser saying the
+ // key is STILL physically down. That makes it exactly the proof the
+ // rescue timer needs, and nothing else: re-render the whole row dozens of
+ // times a second for an unchanged chord and the app crawls while the
+ // recorder is open.
+ if (e.repeat) {
+ armRescue();
+ return;
+ }
pressed.add(e.code);
setPressedCodes(new Set(pressed)); // live keyboard highlight
const tok = codeToKeyToken(e.code);
@@ -432,14 +490,7 @@ export function KeybindRow({
setCombo(next); // live preview as the chord grows
setSaved(false);
}
- // Fallback: some keys — function keys especially, and any key whose
- // release lands while the window is losing focus — do NOT reliably
- // deliver a keyup. Without this the "commit on full release" path below
- // would hang forever ("F5+F6 never records"). Re-arm an idle timer on
- // every keydown; once the user stops pressing for ~900 ms, commit the
- // chord we have even if a keyup never came.
- if (idle) clearTimeout(idle);
- idle = setTimeout(commit, 900);
+ armRescue();
}
function onKeyUp(e: KeyboardEvent) {
@@ -450,6 +501,53 @@ export function KeybindRow({
// Fast path: commit the instant EVERY key is released. `pending` holds
// the fullest chord seen during the gesture, so the release order never
// matters and early-lifted keys are not lost.
+ if (pressed.size === 0 && pending) {
+ if (idle) clearTimeout(idle);
+ commit();
+ return;
+ }
+ armRescue();
+ }
+
+ /**
+ * The window losing focus ends the gesture whether the keys came up or not:
+ * the keyups are delivered to whatever took focus, so waiting for them
+ * would leave the recorder armed forever. This is the honest end of the
+ * one case a timer must not resolve — a held modifier whose release we will
+ * never see (pressing the Windows key opens Start and takes focus with it).
+ */
+ function onWindowBlur() {
+ if (idle) clearTimeout(idle);
+ commit();
+ }
+
+ /**
+ * Drop modifiers from the held set that a mouse event proves are already up.
+ *
+ * Every mouse event carries the TRUE modifier state, so this is a free,
+ * continuous repair for a swallowed modifier keyup — and a held modifier is
+ * exactly what suppresses the rescue timer, so without it the recorder
+ * could sit armed with a phantom Ctrl and no way out but Esc.
+ */
+ function syncModifiers(e: MouseEvent) {
+ let changed = false;
+ for (const code of [...pressed]) {
+ const stillDown = code.startsWith("Control")
+ ? e.ctrlKey
+ : code.startsWith("Alt")
+ ? e.altKey
+ : code.startsWith("Shift")
+ ? e.shiftKey
+ : code.startsWith("Meta")
+ ? e.metaKey
+ : true; // not a modifier — a mouse event says nothing about it
+ if (!stillDown) {
+ pressed.delete(code);
+ changed = true;
+ }
+ }
+ if (!changed) return;
+ setPressedCodes(new Set(pressed));
if (pressed.size === 0 && pending) {
if (idle) clearTimeout(idle);
commit();
@@ -491,8 +589,7 @@ export function KeybindRow({
setCombo(next);
setSaved(false);
}
- if (idle) clearTimeout(idle);
- idle = setTimeout(commit, 900);
+ armRescue();
}
function onMouseUp(e: MouseEvent) {
@@ -505,7 +602,9 @@ export function KeybindRow({
if (pressed.size === 0 && pending) {
if (idle) clearTimeout(idle);
commit();
+ return;
}
+ armRescue();
}
// The side buttons are Back/Forward and the middle button starts autoscroll;
@@ -522,6 +621,8 @@ export function KeybindRow({
window.addEventListener("mousedown", onMouseDown, true);
window.addEventListener("mouseup", onMouseUp, true);
window.addEventListener("auxclick", onAuxClick, true);
+ window.addEventListener("mousemove", syncModifiers, true);
+ window.addEventListener("blur", onWindowBlur);
return () => {
if (idle) clearTimeout(idle);
window.removeEventListener("keydown", onKeyDown, true);
@@ -529,6 +630,8 @@ export function KeybindRow({
window.removeEventListener("mousedown", onMouseDown, true);
window.removeEventListener("mouseup", onMouseUp, true);
window.removeEventListener("auxclick", onAuxClick, true);
+ window.removeEventListener("mousemove", syncModifiers, true);
+ window.removeEventListener("blur", onWindowBlur);
};
}, [capturing]);
@@ -616,18 +719,35 @@ export function KeybindRow({
// ONE stable status line: the blocking message when there is one, otherwise
// the cautions, otherwise the recording hint. Two separately appearing lines
// made the keyboard below jump vertically on every combo click.
- const statusLine = (capturing || validationMsg) && (
+ //
+ // While keys are physically DOWN the chord is still being built, so the line
+ // says so and nothing else. A caution about the half-built state ("a
+ // modifier-only shortcut fires on any superset") judges something the user
+ // has not decided yet — it belongs to the combo they let go of, not to the
+ // one they are still assembling. A blocking collision keeps speaking, since
+ // that is the one thing that will stop the save.
+ const holding = capturing && pressedCodes.size > 0;
+ const isError = !!validationMsg && validation.status === "error";
+ const showValidation = !!validationMsg && (isError || !holding);
+ const statusText = showValidation
+ ? validationMsg
+ : holding
+ ? t("settings_view.keybinds.record_prompt_holding")
+ : capturing
+ ? t("settings_view.keybinds.record_prompt_hint")
+ : null;
+ const statusLine = statusText && (
<p
- data-testid={validationMsg ? `keybind-validation-${action}` : undefined}
+ data-testid={showValidation ? `keybind-validation-${action}` : undefined}
className={`mt-2 text-[11px] ${
- validationMsg
- ? validation.status === "error"
+ showValidation
+ ? isError
? "text-destructive"
: "text-amber-400"
: "text-muted-foreground"
}`}
>
- {validationMsg ?? t("settings_view.keybinds.record_prompt_hint")}
+ {statusText}
</p>
);