X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfind.cpp;h=2ddedcb4818bf21d37ae1c406fd7de9326990cd5;hb=9ec80456feed688440360e0a493cbf537c4fe5f9;hp=c8fc40947e75643cb281589fc41b62b30508858c;hpb=337cc97174e63dfbcdfdf9dd063b425882399b64;p=lyx.git diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index c8fc40947e..2ddedcb481 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -57,13 +57,8 @@ //#define ResultsDebug #define USE_QT_FOR_SEARCH #if defined(USE_QT_FOR_SEARCH) - #include // sets QT_VERSION - #if (QT_VERSION >= 0x050000) - #include - #define QTSEARCH 1 - #else - #define QTSEARCH 0 - #endif + #include + #define QTSEARCH 1 #else #define QTSEARCH 0 #endif @@ -338,7 +333,7 @@ bool findOne(BufferView * bv, docstring const & searchstr, if (match_len > 0) bv->putSelectionAt(cur, match_len, !forward); - else if (onlysel) { + else if (onlysel && bv->cursor().selection()) { docstring q = _("The search string was not found within the selection.\n" "Continue search outside?"); int search_answer = frontend::Alert::prompt(_("Search outside selection?"), @@ -902,7 +897,7 @@ string correctRegex(string t, bool withformat) } else { if (sub.str(4) == "backslash") { - replace = "\\"; + replace = string("\\"); { // transforms '\backslash \{' into '\{' string next = t.substr(sub.position(2) + sub.str(2).length(), 2); @@ -4372,15 +4367,20 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) { if (!cur) return 0; - bool repeat = false; + int repeat = 0; DocIterator orig_cur; // to be used if repeat not successful MatchResult orig_mres; + do { + orig_cur = cur; + cur.forwardPos(); + } while (cur.depth() > orig_cur.depth()); + cur = orig_cur; while (!theApp()->longOperationCancelled() && cur) { //(void) findAdvForwardInnermost(cur); LYXERR(Debug::FINDVERBOSE, "findForwardAdv() cur: " << cur); MatchResult mres = match(cur, -1, MatchStringAdv::MatchAnyPlace); string msg = "Starting"; - if (repeat) + if (repeat > 0) msg = "Repeated"; displayMres(mres, msg + " findForwardAdv", cur) int match_len = mres.match_len; @@ -4389,8 +4389,13 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) match_len = 0; } if (match_len <= 0) { - // This should exit nested insets, if any, or otherwise undefine the currsor. - cur.pos() = cur.lastpos(); + if (repeat > 0) { + repeat--; + } + else { + // This should exit nested insets, if any, or otherwise undefine the currsor. + cur.pos() = cur.lastpos(); + } LYXERR(Debug::FINDVERBOSE, "Advancing pos: cur=" << cur); cur.forwardPos(); } @@ -4418,7 +4423,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) cur.pos() = cur.pos() + increment; MatchResult mres2 = match(cur, -1, MatchStringAdv::MatchAnyPlace); displayMres(mres2, "findForwardAdv loop", cur) - switch (interpretMatch(mres, mres2)) { + switch (interpretMatch(mres, mres2)) { case MatchResult::newIsTooFar: // behind the expected match firstInvalid = increment; @@ -4426,7 +4431,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) increment /= 2; break; case MatchResult::newIsBetter: - // not reached yet, but cur.pos()+increment is bettert + // not reached yet, but cur.pos()+increment is better mres = mres2; firstInvalid -= increment; if (increment > firstInvalid*3/4) @@ -4449,14 +4454,14 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) if (mres.match_len > 0) { if (mres.match_prefix + mres.pos - mres.leadsize > 0) { // The match seems to indicate some deeper level - repeat = true; + repeat = 2; orig_cur = cur; orig_mres = mres; cur.forwardPos(); continue; } } - else if (repeat) { + else if (repeat > 0) { // should never be reached. cur = orig_cur; mres = orig_mres;