Skip to content

Keep preview shortcuts working after clicking Pause - #66

Merged
blixvip merged 1 commit into
blixvip:mainfrom
hussain-alsaibai:fix/demo-shortcuts-after-pause
Nov 15, 2026
Merged

blixvip merged 1 commit into
blixvip:mainfrom
hussain-alsaibai:fix/demo-shortcuts-after-pause

Conversation

@hussain-alsaibai

Copy link
Copy Markdown
Contributor

Fixes #59.

What was wrong

The homepage keydown handler bailed out before any shortcut ran:

// public/demo.mjs:169-170
document.addEventListener('keydown', event => {
  if (event.target.closest('button, input, a')) return;

The play/pause control (#final-toggle) is a <button>, and so is every library card. Clicking either one leaves it focused, so event.target is that button on the next keypress and the handler returns early. That silently disabled ,, ., Home, End, ArrowLeft and ArrowRight for the exact flow the README documents — "Pause the film, then press , to step back one frame" — because pausing by clicking the on-screen button is the obvious way to pause.

The guard exists to avoid hijacking typed text, which only needs to cover text entry.

What this changes

  • public/demo.mjs — the guard is now isTextEntry(target): it skips textarea, select, text-like input, and [contenteditable] (including a caret inside one). Non-text inputs — checkbox, radio, range, file, button, submit, reset, color, hidden — do not accept typed text, so they no longer swallow the shortcuts.
  • Space keeps the old button, a exclusion, as the issue asked. A focused button activates natively on Space, so also calling final-toggle.click() toggled playback twice. That is the one case where the old exclusion was correct and it is preserved deliberately.
  • The exporting / !sections.length early return is untouched.

How to verify

test/demo-shortcuts.test.js — 9 cases covering the reported bug and the surrounding contract:

  • a focused pause <button> no longer counts as text entry (this is the bug)
  • a library card and a link do not block the arrows
  • every text-like input type, textarea, select and contenteditable (plus a child of it) still get their keys
  • non-text input types let the shortcuts through
  • a plain non-editable <div> and an unknown target do not block
  • Space is left to native activation on a button/link and handled by the page otherwise (the double-fire guard)

The two decision functions are exported and exercised through a small DOM shim rather than by regexing the source. The existing tests in this repo check source shape with regexes; that style cannot catch a guard that is present but wrong, which is what this bug was.

node --test test/demo-shortcuts.test.js   # 9 pass
npm run check                             # Checked 47 UI files
npm test                                  # 34 pass, 2 fail

The two failures are extractAudio reuses cached files… and reference audio route extracts missing audio once…. Both fail identically on a clean checkout in this environment because ffmpeg is not installed here — they are unrelated to this change.

I did not verify the manual browser steps in the issue (no browser in this environment); the behaviour above is covered by the unit tests instead.

The homepage keydown handler returned early whenever the focused element was
a button, input or link:

  if (event.target.closest('button, input, a')) return;

The play/pause control is a <button>, and so is every library card. Clicking
either one left it focused, so event.target was that button on the next
keypress and the handler bailed before reaching any shortcut. That breaks the
flow the README documents: pause with the on-screen button, then press "," or
"." to step a frame. Home, End and the left/right arrows were disabled the
same way.

The guard only needs to protect typed text, so narrow it to text entry:

- isTextEntry() skips textarea, select, a text-like input and contenteditable.
  Checkboxes, radios, ranges, files and buttons-as-input do not accept typed
  text and must not swallow the shortcuts.
- Space keeps the old button/link exclusion: a focused button activates
  natively, and also calling final-toggle.click() toggled playback twice.

Tests in test/demo-shortcuts.test.js, 9 cases, including the reported one
(focused pause button) and the double-fire guard for Space. The decision
functions are exercised through a small DOM shim rather than by regexing the
source, so a guard that is present but wrong cannot pass.

@blixvip blixvip left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hussain-alsaibai, this is careful work. The guard does what #59 asked, Space stays single-fire, and I like that the tests run the real function bodies instead of regexing the source. Locally npm test is 36/36 and npm run check is clean.

One real regression to fix before I merge, and the issue text didn't warn you about it, so that's on us:

The seek slider loses its arrow keys. #seek in public/demo.html is an <input type="range">. With the old guard, a focused slider kept its native behaviour: Left/Right stepped the playhead by 0.01 s, which is how keyboard users scrub. With this PR, range no longer counts as text entry, so after you click or tab to the slider, Left/Right reach the handler, preventDefault() runs, and the playhead jumps a whole section instead. , . Home and End on a focused slider are fine as they are now (Home/End do the same thing natively).

Small fix, right after the isTextEntry check in the keydown handler:

  if (isTextEntry(event.target)) return;
  // A focused range slider (#seek) keeps its own arrow keys: that is how keyboard users scrub.
  if (event.code.startsWith('Arrow') && event.target.closest?.('input[type="range"]')) return;

I tried exactly this on your branch and all 36 tests still pass. If you want to cover it, a small exported helper like spaceHandledNatively (say arrowsHandledNatively(target)) would fit your existing test style, but that's optional.

Minor and optional: closest('[contenteditable]') also matches contenteditable="false". Nothing on the page uses that today, so I wouldn't hold the PR for it.

Push the slider fix and I'll merge it straight away.

@blixvip

blixvip commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks for the fix! Reviewed and merging. 🙏

@blixvip
blixvip merged commit a7f96c9 into blixvip:main Nov 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep the preview page's frame-step and section shortcuts working after clicking Pause

2 participants