From: Kornel Benko Date: Wed, 5 Dec 2018 12:36:43 +0000 (+0100) Subject: FindAdv: Simplify search for chars '&', '%', '#' and '_' X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a9422decbdeb6011e60fb82a5285b99d4b961f50;p=features.git FindAdv: Simplify search for chars '&', '%', '#' and '_' This is not possible for '$', because of the latex-meaning to start/end math inset. Therefore, if not ignoring format, we still have to use [\\][\$] in regex in order to find '$' in text. --- diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 5bad896dfd..329bbfd010 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -1297,9 +1297,17 @@ void Paragraph::Private::latexSpecialChar(otexstream & os, column += 14; break; - case '$': case '&': - case '%': case '#': case '{': - case '}': case '_': + case '&': + case '%': case '#': + case '_': + if (runparams.for_search) { + os.put(c); + column += 1; + break; + } + // fall through + case '$': + case '{': case '}': os << '\\'; os.put(c); column += 1; diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 113ba77fc7..9ac768060f 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -74,19 +74,19 @@ void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const os << '{'; } - odocstringstream ourplain; - InsetText::plaintext(ourplain, runparams); + odocstringstream ourlatex; + otexstream ots(ourlatex); + InsetText::latex(ots, runparams); if (runparams.for_search) { // No need for special handling, if we are only searching for some patterns - os << ourplain.str() << "}"; + os << ourlatex.str() << "}"; return; } // get contents of InsetText as LaTeX and plaintext - odocstringstream ourlatex; + odocstringstream ourplain; + InsetText::plaintext(ourplain, runparams); // FIXME: do Tex/Row correspondence (I don't currently understand what is // being generated from latexstr below) - otexstream ots(ourlatex); - InsetText::latex(ots, runparams); docstring latexstr = ourlatex.str(); docstring plainstr = ourplain.str(); diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 378b1c1d02..36ed47bd2a 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -1442,8 +1442,16 @@ void LatexInfo::buildEntries(bool isPatternString) if (key == "") { if (sub.str(0)[0] == '\\') key = sub.str(0)[1]; - else + else { key = sub.str(0); + if (key == "$") { + size_t k_pos = sub.position(size_t(0)); + if ((k_pos > 0) && (interval.par[k_pos - 1] == '\\')) { + // Escaped '$', ignoring + continue; + } + } + } }; if (evaluatingRegexp) { if (sub.str(1).compare("endregexp") == 0) {