]> git.sesse.net Git - remoteglot/commitdiff
Fix a super-long-standing bug, where making a move on the board could make us replay...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 24 Dec 2022 10:38:56 +0000 (11:38 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 24 Dec 2022 10:38:56 +0000 (11:38 +0100)
www/js/remoteglot.js

index d6292c3c8077e63ee5371347fa3d303a8602d08c..ee7495f1b138329f857fe0db1e9e8d2a58461176 100644 (file)
@@ -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;
                }
        }