From 63f0747ccbade6ca2a634b18be8c429f775441d8 Mon Sep 17 00:00:00 2001 From: Nathanael Anderson Date: Sun, 6 Sep 2026 19:10:23 -0400 Subject: [PATCH] Give the keyboard back after using the seek bar Clicking the seek bar disabled Space and the arrow keys for the rest of the session. transportHotkeys stands down whenever the event target is an , which a range slider is, and a range natively eats arrow keys to drive its own thumb -- so focus landing there took the transport keys with it. The control added for moving around a song was the one thing that stopped you moving around a song with the keyboard. The guard is not wrong: a slider that the user has deliberately tabbed to should own its arrow keys. So the fix is at the other end -- the seek bar releases focus when the pointer lifts. Click it and the hotkeys come straight back; tab to it and arrow-key adjustment still works, which is the case the guard exists for. The same trap is waiting in every other slider on the play surface (song volume, metronome, piano gain, spacing). They are less exposed because nobody clicks them mid-song, and they are left alone here rather than swept up. Pinned in transportHotkeys.test.ts, where the guard lives, so the next person to add a slider meets this in a test rather than in the app. Co-Authored-By: Claude Opus 5 --- apps/game/src/main.ts | 17 ++++++++++++-- apps/game/tests/transportHotkeys.test.ts | 29 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/apps/game/src/main.ts b/apps/game/src/main.ts index 3073aca..73c45e6 100644 --- a/apps/game/src/main.ts +++ b/apps/game/src/main.ts @@ -2000,9 +2000,22 @@ if (songScrubRangeEl) { scrubbing = false; seekFromScrub(); }; + // Hand focus back after a click. + // + // transportHotkeys treats every as typing and stands down, and a + // range natively eats arrow keys to move its own thumb. So a slider that + // keeps focus after a click silently disables Space and Left/Right for the + // rest of the session -- and this is the seek bar, which is exactly what + // someone reaches for when they want to move around a song. Releasing focus + // on pointer release restores the hotkeys; deliberately tabbing here still + // holds focus, so arrow-key adjustment stays available to keyboard users. + const releaseAfterPointer = () => { + commit(); + songScrubRangeEl.blur(); + }; songScrubRangeEl.addEventListener("change", commit); - songScrubRangeEl.addEventListener("pointerup", commit); - songScrubRangeEl.addEventListener("pointercancel", commit); + songScrubRangeEl.addEventListener("pointerup", releaseAfterPointer); + songScrubRangeEl.addEventListener("pointercancel", releaseAfterPointer); songScrubRangeEl.addEventListener("blur", commit); } diff --git a/apps/game/tests/transportHotkeys.test.ts b/apps/game/tests/transportHotkeys.test.ts index 220cfe5..de3c72d 100644 --- a/apps/game/tests/transportHotkeys.test.ts +++ b/apps/game/tests/transportHotkeys.test.ts @@ -181,6 +181,35 @@ describe("transportHotkeys", () => { expect(h.tc.seek).not.toHaveBeenCalled(); }); + // A slider counts as "typing" here, which is how the seek bar disabled the + // very hotkeys it sits next to: clicking it left focus on a range input, + // and from then on Space and the arrows were swallowed for the rest of the + // session. The guard is not wrong -- a focused slider should own its own + // arrow keys -- so the fix belongs at the other end: whoever adds a slider + // to the play surface has to hand focus back after a pointer interaction. + // This pins the trap so the next person meets it here rather than in the + // app. + it("stands down for a focused range slider, which is why sliders must release focus", () => { + const h = setup({}, { t: 30, isPlaying: true }); + const slider = document.createElement("input"); + slider.type = "range"; + document.body.appendChild(slider); + slider.dispatchEvent( + new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true, cancelable: true }), + ); + slider.dispatchEvent( + new KeyboardEvent("keydown", { key: " ", bubbles: true, cancelable: true }), + ); + expect(h.tc.seek).not.toHaveBeenCalled(); + expect(h.tc.pause).not.toHaveBeenCalled(); + + // …and once focus is elsewhere the hotkeys are live again. + document.body.dispatchEvent( + new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true, cancelable: true }), + ); + expect(h.tc.seek).toHaveBeenCalledTimes(1); + }); + it("ignores keys in a contenteditable element", () => { const h = setup({}, { t: 0, isPlaying: false }); const el = document.createElement("div");