From c041bb667a009459b17e24957c1d5147c2149dab Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Wed, 20 Jan 2021 12:24:33 +0100 Subject: [PATCH] FindAdv: Fix interpretation of match-results 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 | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 42726435e7..0b252f3a83 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -52,7 +52,7 @@ #include #include -//#define ResultsDebug +#define ResultsDebug #define USE_QT_FOR_SEARCH #if defined(USE_QT_FOR_SEARCH) #include // 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"); -- 2.39.2