Repository navigation
Keep preview shortcuts working after clicking Pause - #66
Conversation
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
left a comment
There was a problem hiding this comment.
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.
|
Thanks for the fix! Reviewed and merging. 🙏 |
Fixes #59.
What was wrong
The homepage keydown handler bailed out before any shortcut ran:
The play/pause control (
#final-toggle) is a<button>, and so is every library card. Clicking either one leaves it focused, soevent.targetis that button on the next keypress and the handler returns early. That silently disabled,,.,Home,End,ArrowLeftandArrowRightfor 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 nowisTextEntry(target): it skipstextarea,select, text-likeinput, 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.Spacekeeps the oldbutton, aexclusion, as the issue asked. A focused button activates natively on Space, so also callingfinal-toggle.click()toggled playback twice. That is the one case where the old exclusion was correct and it is preserved deliberately.exporting/!sections.lengthearly return is untouched.How to verify
test/demo-shortcuts.test.js— 9 cases covering the reported bug and the surrounding contract:<button>no longer counts as text entry (this is the bug)inputtype,textarea,selectandcontenteditable(plus a child of it) still get their keysinputtypes let the shortcuts through<div>and an unknown target do not blockSpaceis 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.
The two failures are
extractAudio reuses cached files…andreference audio route extracts missing audio once…. Both fail identically on a clean checkout in this environment becauseffmpegis 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.