commit cd94180492e47b4017fcbb5c81f19c8433a87baa
Author: Kornel Benko <[email protected]>
Date: Wed Dec 5 13:36:43 2018 +0100
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.
---
src/Paragraph.cpp | 14 +++++++++++---
src/insets/InsetIndex.cpp | 12 ++++++------
src/lyxfind.cpp | 10 +++++++++-
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 5bad896..329bbfd 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 113ba77..9ac7680 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 378b1c1..36ed47b 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) {