Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions apps/game/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2000,9 +2000,22 @@ if (songScrubRangeEl) {
scrubbing = false;
seekFromScrub();
};
// Hand focus back after a click.
//
// transportHotkeys treats every <input> 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);
}

Expand Down
29 changes: 29 additions & 0 deletions apps/game/tests/transportHotkeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading