Fix scrolling to game beginning
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 6 Mar 2020 18:20:52 +0000 (19:20 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 6 Mar 2020 18:20:52 +0000 (19:20 +0100)
client/src/components/MoveList.vue

index 228971a..4357098 100644 (file)
@@ -108,9 +108,13 @@ export default {
       if (window.innerWidth <= 767) return; //scrolling would hide chessboard
       // $nextTick to wait for table > tr to be rendered
       this.$nextTick(() => {
-        let curMove = document.querySelector(".td.highlight-lm");
-        if (curMove) {
-          curMove.scrollIntoView({
+        let curLine = document.querySelector(".td.highlight-lm");
+        if (!!curLine) curLine = curLine.parentNode;
+        if (!curLine && this.moves.length > 0)
+          // Cursor is before game beginning, and some moves were made:
+          curLine = document.querySelector(".moves-list .tr:first-child")
+        if (!!curLine) {
+          curLine.scrollIntoView({
             behavior: "auto",
             block: "nearest"
           });