From 8a081ee7e5002aa4ded8e0ac9cdd08a8ca8c80a5 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 24 Dec 2022 11:38:56 +0100 Subject: [PATCH] Fix a super-long-standing bug, where making a move on the board could make us replay the game from the start. --- www/js/remoteglot.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index d6292c3..ee7495f 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -2178,6 +2178,8 @@ let onSnapEnd = function(source, target) { promotion: 'q' // NOTE: always promote to a queen for example simplicity }); + // Move ahead on the line we're on -- this includes history if we've + // gone backwards. if (current_display_line && current_display_move < current_display_line.pv.length - 1 && current_display_line.pv[current_display_move + 1] === move.san) { @@ -2187,15 +2189,16 @@ let onSnapEnd = function(source, target) { // Walk down the displayed lines until we find one that starts with // this move, then select that. Note that this gives us a good priority - // order (history first, then PV, then multi-PV lines). - for (let i = 0; i < display_lines.length; ++i) { + // order (PV, then multi-PV lines; history was already dealt with above, + // as it's the only line that originates backwards). + for (let i = 1; i < display_lines.length; ++i) { if (i == 1 && current_display_line) { // Do not choose PV if not on it. continue; } let line = display_lines[i]; if (line.pv[line.start_display_move_num] === move.san) { - show_line(i, 0); + show_line(i, line.start_display_move_num); return; } } -- 2.39.2