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");