FindAdv: Handle search for '{' and '}'

In format-search the chars '{' and '}' are understood as latex parentheses, which normally are not
part of text and are discarded.
Instead we fake them as if they were a char like \backslash or \guilemotright or such.
This commit is contained in:
Kornel Benko 2021-01-18 01:10:07 +01:00
parent a4e6f0dead
commit ec387b6d65
2 changed files with 17 additions and 3 deletions

View File

@ -1132,8 +1132,16 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
if (style.pass_thru || runparams.pass_thru || runparams.for_search if (style.pass_thru || runparams.pass_thru || runparams.for_search
|| contains(style.pass_thru_chars, c) || contains(style.pass_thru_chars, c)
|| contains(runparams.pass_thru_chars, c)) { || contains(runparams.pass_thru_chars, c)) {
if ((c == '\\') && runparams.for_search) if (runparams.for_search) {
if (c == '\\')
os << "\\\\"; os << "\\\\";
else if (c == '{')
os << "\\braceleft";
else if (c == '}')
os << "\\braceright";
else if (c != '\0')
os.put(c);
}
else if (c != '\0') { else if (c != '\0') {
Encoding const * const enc = runparams.encoding; Encoding const * const enc = runparams.encoding;
if (enc && !enc->encodable(c)) if (enc && !enc->encodable(c))

View File

@ -778,6 +778,10 @@ string correctRegex(string t)
replace = "\\"; replace = "\\";
else if (sub.str(4) == "mathcircumflex") else if (sub.str(4) == "mathcircumflex")
replace = "^"; replace = "^";
else if (sub.str(3) == "{")
replace = "\\braceleft";
else if (sub.str(3) == "}")
replace = "\\braceright";
else else
replace = sub.str(3); replace = sub.str(3);
} }
@ -2238,6 +2242,7 @@ void LatexInfo::buildKeys(bool isPatternString)
// Known charaters // Known charaters
// No split // No split
makeKey("backslash|textbackslash|slash", KeyInfo(KeyInfo::isChar, 0, false), isPatternString); makeKey("backslash|textbackslash|slash", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
makeKey("braceleft|braceright", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
makeKey("textasciicircum|textasciitilde", KeyInfo(KeyInfo::isChar, 0, false), isPatternString); makeKey("textasciicircum|textasciitilde", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
makeKey("textasciiacute|texemdash", KeyInfo(KeyInfo::isChar, 0, false), isPatternString); makeKey("textasciiacute|texemdash", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
makeKey("dots|ldots", KeyInfo(KeyInfo::isChar, 0, false), isPatternString); makeKey("dots|ldots", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
@ -2931,6 +2936,7 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with
return ""; return "";
} }
} }
} }
else { else {
// LYXERR(Debug::INFO, "No regex formats"); // LYXERR(Debug::INFO, "No regex formats");
@ -3316,7 +3322,7 @@ MatchResult MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_be
int matchend = match.capturedEnd(0); int matchend = match.capturedEnd(0);
while (mres.match_len > 0) { while (mres.match_len > 0) {
QChar c = qstr.at(matchend - 1); QChar c = qstr.at(matchend - 1);
if ((c == '\n') || (c == '}') || (c == '{')) { if (c == '\n') {
mres.match_len--; mres.match_len--;
matchend--; matchend--;
} }