]> git.lyx.org Git - features.git/commitdiff
FindAdv: Fix interpretation of match-results
authorKornel Benko <kornel@lyx.org>
Wed, 20 Jan 2021 11:24:33 +0000 (12:24 +0100)
committerKornel Benko <kornel@lyx.org>
Wed, 20 Jan 2021 11:41:37 +0000 (12:41 +0100)
Since commit c600906d92d all matches are match-results of examined strings starting
with a character of the same cursor depth, we can be sure to match the same string again if:
1.) the number of characters to the end of the examined strings match.
2.) the match-lengths are identical

src/lyxfind.cpp

index 42726435e7f3c48caed4f6fe40753c5004d329d4..0b252f3a838cc3b3295428c2e45a8d85f5cbeab1 100644 (file)
@@ -52,7 +52,7 @@
 #include <map>
 #include <regex>
 
-//#define ResultsDebug
+#define ResultsDebug
 #define USE_QT_FOR_SEARCH
 #if defined(USE_QT_FOR_SEARCH)
        #include <QtCore>       // sets QT_VERSION
@@ -782,16 +782,13 @@ public:
 
 static MatchResult::range interpretMatch(MatchResult &oldres, MatchResult &newres)
 {
-  int range = oldres.match_len;
-  if (range > 0) range--;
-  if (newres.match2end < oldres.match2end - range)
+  if (newres.match2end < oldres.match2end)
     return MatchResult::newIsTooFar;
   if (newres.match_len < oldres.match_len)
     return MatchResult::newIsTooFar;
+
   if (newres.match_len == oldres.match_len) {
-    if ((newres.match2end == oldres.match2end) ||
-      ((newres.match2end < oldres.match2end + range) &&
-       (newres.match2end > oldres.match2end - range)))
+    if (newres.match2end == oldres.match2end)
       return MatchResult::newIsBetter;
   }
   return MatchResult::newIsInvalid;
@@ -3593,6 +3590,8 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
        if (!cur)
                return 0;
        bool repeat = false;
+       DocIterator orig_cur;   // to be used if repeat not successful
+       MatchResult orig_mres;
        while (!theApp()->longOperationCancelled() && cur) {
                //(void) findAdvForwardInnermost(cur);
                LYXERR(Debug::FIND, "findForwardAdv() cur: " << cur);
@@ -3675,10 +3674,19 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
                                        }
                                }
                        }
-                       if (mres.match_len > 0 && mres.match_prefix + mres.pos - mres.leadsize > 0) {
-                               repeat = true;
-                               cur.forwardPos();
-                               continue;
+                       if (mres.match_len > 0) {
+                               if (mres.match_prefix + mres.pos - mres.leadsize > 0) {
+                                       repeat = true;
+                                       orig_cur = cur;
+                                       orig_mres = mres;
+                                       cur.forwardPos();
+                                       continue;
+                               }
+                       }
+                       else if (repeat) {
+                               // seems to never be reached.
+                               cur = orig_cur;
+                               mres = orig_mres;
                        }
                        // LYXERR0("Leaving first loop");
                        LYXERR(Debug::FIND, "Finalizing 1");