Skip to content

Conversation

@johndoknjas
Copy link
Contributor

@johndoknjas johndoknjas commented Dec 11, 2024

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() in bindMobileMousedown, which is needed for a couple reasons.

),
hook: onInsert(el => {
el.addEventListener('mousedown', goThroughMoves(ctrl));
el.addEventListener('touchstart', goThroughMoves(ctrl));
Copy link
Collaborator

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?

const delay = showMovesDecreasingDelay();
document.addEventListener(e.type === 'touchstart' ? 'touchend' : 'mouseup', () => clearMovesTimeout(), {
once: true,
});
Copy link
Collaborator

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?

@johndoknjas johndoknjas marked this pull request as draft December 12, 2024 00:00
@johndoknjas johndoknjas marked this pull request as ready for review December 12, 2024 20:35
@johndoknjas johndoknjas marked this pull request as draft December 12, 2024 21:18
@johndoknjas johndoknjas marked this pull request as ready for review December 12, 2024 21:53
@johndoknjas johndoknjas marked this pull request as draft December 13, 2024 12:06
@johndoknjas johndoknjas marked this pull request as ready for review December 13, 2024 12:14
Copy link
Collaborator

@ornicar ornicar left a 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';
Copy link
Collaborator

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()?

Copy link
Contributor Author

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.

image

@ornicar ornicar merged commit 63ddf2e into lichess-org:master Dec 14, 2024
3 checks 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.

On mobile, holding the move back and forward buttons has no effect

2 participants