Force Move History refresh after loading/reverting variation
[xboard.git] / history.c
index 4598799..7c64582 100644 (file)
--- a/history.c
+++ b/history.c
@@ -28,7 +28,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <malloc.h>
 #include <string.h>
 
 #include "common.h"
@@ -51,6 +50,7 @@ typedef char MoveHistoryString[ MOVE_LEN*2 ];
 static int lastFirst = 0;
 static int lastLast = 0;
 static int lastCurrent = -1;
+static int lastGames;
 
 static char lastLastMove[ MOVE_LEN ];
 
@@ -80,7 +80,7 @@ static Boolean OnlyCurrentPositionChanged()
         currFirst == lastFirst &&
         currLast == lastLast &&
         currCurrent >= 0 &&
-        TRUE )
+        lastGames == storedGames )
     {
         result = TRUE;
 
@@ -106,7 +106,7 @@ static Boolean OneMoveAppended()
         lastLast == (currLast-1) &&
         lastCurrent == (currCurrent-1) &&
         currCurrent == (currLast-1) &&
-        TRUE )
+        lastGames == storedGames )
     {
         result = TRUE;
     }
@@ -132,7 +132,7 @@ static void AppendMoveToMemo( int index )
     }
 
     /* Move text */
-    strcpy( buf, SavePart( currMovelist[index] ) );
+    safeStrCpy( buf, SavePart( currMovelist[index]) , sizeof( buf)/sizeof( buf[0]) );
     strcat( buf, " " );
 
     histMoves[index].memoOffset = AppendToHistoryMemo( buf, 0, 0 );
@@ -175,16 +175,16 @@ void MemoContentUpdated()
 {
     int caretPos;
 
-    DoHighlight( lastCurrent, FALSE );
-    DoHighlight( currCurrent, TRUE );
+    if(lastCurrent <= currLast) DoHighlight( lastCurrent, FALSE );
 
     lastFirst = currFirst;
     lastLast = currLast;
     lastCurrent = currCurrent;
+    lastGames = storedGames;
     lastLastMove[0] = '\0';
 
     if( lastLast > 0 ) {
-        strcpy( lastLastMove, SavePart( currMovelist[lastLast-1] ) );
+      safeStrCpy( lastLastMove, SavePart( currMovelist[lastLast-1] ) , sizeof( lastLastMove)/sizeof( lastLastMove[0]) );
     }
 
     /* Deselect any text, move caret to end of memo */
@@ -196,6 +196,7 @@ void MemoContentUpdated()
     }
 
     ScrollToCurrent(caretPos);
+    DoHighlight( currCurrent, TRUE ); // [HGM] moved last, because in X some scrolling methods spoil highlighting
 }
 
 // back-end. Must be called as double-click call-back on move-history text edit