From 8c501308c3c9bf2389275837798ed6c62a9a17bf Mon Sep 17 00:00:00 2001 From: Alexander Dunlap Date: Mon, 10 Jun 2024 14:42:29 +0200 Subject: [PATCH] FindAdv: Omitting cursor advance at start of search if in mathed. Fixes #13070 Advanced S&R does not find math symbols at start of document --- src/lyxfind.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index a42fc4e1dc..aae8b30bff 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -4114,7 +4114,13 @@ string MatchStringAdv::convertLF2Space(docstring const &s, bool ignore_format) c static string showPos(DocIterator const & cur) { stringstream a; - a << "[idx(" << cur.idx() << "),pit(" << cur.pit() << "),pos(" << cur.pos() << "),depth(" << cur.depth() << ")]"; + string inmath; + if (cur.inMathed()) + inmath = "inMath"; + else + inmath = "inText"; + + a << "[idx(" << cur.idx() << "),pit(" << cur.pit() << "),pos(" << cur.pos() << "),depth(" << cur.depth() << ") " << inmath << ")]"; return(a.str()); } @@ -4147,7 +4153,7 @@ docstring stringifyFromCursor(DocIterator const & cur, int len) docstring res = from_utf8(latexNamesToUtf8(par.asString(cur.pos(), end, option, &runparams), false)); - LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Stringified text from pos(" << cur.pos() << ") len(" << len << "): " << res); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Stringified text from " << showPos(cur) << " len(" << len << "): " << res); return res; } else if (cur.inMathed()) { CursorSlice cs = cur.top(); @@ -4203,7 +4209,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len) endpos = cur.pos() + len; TeXOnePar(buf, *cur.innerText(), cur.pit(), os, runparams, string(), cur.pos(), endpos, true); - LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Latexified text from pos(" << cur.pos() << ") len(" << len << "): " << ods.str()); + LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Latexified text from " << showPos(cur) << ods.str()); return(ods.str()); } else if (cur.inMathed()) { // Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly @@ -4441,7 +4447,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) do { orig_cur = cur; cur.forwardPos(); - } while (cur.depth() > orig_cur.depth()); + } while (cur.depth() > orig_cur.depth() && !cur.inMathed()); cur = orig_cur; while (!theApp()->longOperationCancelled() && cur) { //(void) findAdvForwardInnermost(cur);