From e9fefaa38e62524c77a1c2e2a6ba14b96a745161 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Tue, 9 Nov 2021 21:08:22 +0100
Subject: [PATCH] Ignoring multiwords while moving word index

---
 reading_machine/src/Config.cpp | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/reading_machine/src/Config.cpp b/reading_machine/src/Config.cpp
index 69ae400..ce6af52 100644
--- a/reading_machine/src/Config.cpp
+++ b/reading_machine/src/Config.cpp
@@ -443,14 +443,34 @@ bool Config::moveWordIndex(int relativeMovement)
   if (!canMoveWordIndex(relativeMovement))
     return false;
 
-  wordIndex += relativeMovement;
+  int dir = 1;
+  if (relativeMovement < 0)
+    dir = -1; 
+
+  int movementDone = 0;
+  if (isMultiwordPredicted(wordIndex))
+    wordIndex += dir;
+  while (movementDone != relativeMovement)
+  {
+    if (isMultiwordPredicted(wordIndex))
+      wordIndex += dir;
+    wordIndex += dir;
+    movementDone += dir;
+    if (isMultiwordPredicted(wordIndex))
+      wordIndex += dir;
+  }
 
   return true;
 }
 
 void Config::moveWordIndexRelaxed(int relativeMovement)
 {
-  while (!moveWordIndex(relativeMovement));
+  int dir = 1;
+  if (relativeMovement < 0)
+    dir = -1;
+  for (int i = 0; i < abs(relativeMovement); i++)
+    if (!moveWordIndex(dir))
+      break;
 }
 
 bool Config::canMoveWordIndex(int relativeMovement) const
-- 
GitLab