-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Holding down forward/backward move buttons #16566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Holding down forward/backward move buttons #16566
Conversation
…mplemented when held horizontally.
ui/round/src/view/replay.ts
Outdated
| ), | ||
| hook: onInsert(el => { | ||
| el.addEventListener('mousedown', goThroughMoves(ctrl)); | ||
| el.addEventListener('touchstart', goThroughMoves(ctrl)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we not using bindMobileMousedown like ui/analyse does?
ui/round/src/view/replay.ts
Outdated
| const delay = showMovesDecreasingDelay(); | ||
| document.addEventListener(e.type === 'touchstart' ? 'touchend' : 'mouseup', () => clearMovesTimeout(), { | ||
| once: true, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code is a bit tricky, and duplicated with the round repeater. Can they be refactored?
…al is to make it easier to combine some of their functionality.
…d in `goToPly` is enough to avoid issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we're almost there!
| let timeout = setTimeout(repeat, delay.next().value!); | ||
| f(); | ||
| if (additionalStopCond?.()) clearTimeout(timeout); | ||
| const eventName = e.type === 'touchstart' ? 'touchend' : 'mouseup'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that repeat() does this:
f();
timeout = setTimeout(repeat, delay.next().value!);
if (additionalStopCond?.()) clearTimeout(timeout);and the code from lines 143 to 145 does this:
let timeout = setTimeout(repeat, delay.next().value!);
f();
if (additionalStopCond?.()) clearTimeout(timeout);Which seems to be the exact same thing? Can we replace these 3 lines with a simple call to repeat()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ornicar Updated to do that. The reason I didn't before is that components.ts did it in a similar way (screenshot), and it makes a very slight difference for time. On my computer, f() usually spends in the neighbourhood of ~8 milliseconds for the analysis board, and somewhere around ~2 ms for the in-progress game board. So setting the timeout after the initial f() will cause this amount of additional delay for the first replayed move.
Resolves #15960.
When viewing live (or just finished) games on a PC/phone, holding down the forward/backward buttons will now cycle through multiple moves. For a phone this works both in vertical and horizontal mode.
One small thing to note is that on a phone, the forward/backward buttons will no longer briefly flash after being clicked (similar to the analysis board buttons). This is because of
e.preventDefault()inbindMobileMousedown, which is needed for a couple reasons.