FindAdv: Add handling of regex char '^' at start also for search with disabled format

lyxfind.cpp:
	handle \mathcircumflex inside regex
output_latex.cpp:
	don't mark extra end of parameters if no options involved
This commit is contained in:
Kornel Benko 2021-01-14 14:44:21 +01:00
parent 9bdd0b31db
commit a7590d33e3
2 changed files with 36 additions and 34 deletions

View File

@ -764,7 +764,7 @@ string correctRegex(string t)
* and \{, \}, \[, \] => {, }, [, ] * and \{, \}, \[, \] => {, }, [, ]
*/ */
string s(""); string s("");
regex wordre("(\\\\)*(\\\\((backslash) ?|[\\[\\]\\{\\}]))"); regex wordre("(\\\\)*(\\\\((backslash|mathcircumflex) ?|[\\[\\]\\{\\}]))");
size_t lastpos = 0; size_t lastpos = 0;
smatch sub; smatch sub;
for (sregex_iterator it(t.begin(), t.end(), wordre), end; it != end; ++it) { for (sregex_iterator it(t.begin(), t.end(), wordre), end; it != end; ++it) {
@ -776,6 +776,8 @@ string correctRegex(string t)
else { else {
if (sub.str(4) == "backslash") if (sub.str(4) == "backslash")
replace = "\\"; replace = "\\";
else if (sub.str(4) == "mathcircumflex")
replace = "^";
else else
replace = sub.str(3); replace = sub.str(3);
} }
@ -2121,7 +2123,7 @@ void LatexInfo::buildEntries(bool isPatternString)
} }
closings = 0; closings = 0;
} }
if (interval_.par.substr(found._dataStart-1, 15).compare("\\endarguments{}") == 0) { if (interval_.par.substr(found._dataStart, 15).compare("\\endarguments{}") == 0) {
found._dataStart += 15; found._dataStart += 15;
} }
size_t endpos; size_t endpos;
@ -3120,9 +3122,9 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt)
++close_wildcards; ++close_wildcards;
} }
*/ */
size_t lng = par_as_string.size();
if (!opt.ignoreformat) { if (!opt.ignoreformat) {
// Remove extra '\}' at end if not part of \{\.\} // Remove extra '\}' at end if not part of \{\.\}
size_t lng = par_as_string.size();
while(lng > 2) { while(lng > 2) {
if (par_as_string.substr(lng-2, 2).compare("\\}") == 0) { if (par_as_string.substr(lng-2, 2).compare("\\}") == 0) {
if (lng >= 6) { if (lng >= 6) {
@ -3137,12 +3139,12 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt)
} }
if (lng < par_as_string.size()) if (lng < par_as_string.size())
par_as_string = par_as_string.substr(0,lng); par_as_string = par_as_string.substr(0,lng);
}
if ((lng > 0) && (par_as_string[0] == '^')) { if ((lng > 0) && (par_as_string[0] == '^')) {
par_as_string = par_as_string.substr(1); par_as_string = par_as_string.substr(1);
--lng; --lng;
opt.matchstart = true; opt.matchstart = true;
} }
}
LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'"); LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
LYXERR(Debug::FIND, "Open braces: " << open_braces); LYXERR(Debug::FIND, "Open braces: " << open_braces);
LYXERR(Debug::FIND, "Replaced text (to be used as regex): " << par_as_string); LYXERR(Debug::FIND, "Replaced text (to be used as regex): " << par_as_string);

View File

@ -549,7 +549,7 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
} }
} }
} }
if (runparams.for_search) { if (runparams.for_search && argnr > 1) {
// Mark end of arguments for findadv() only // Mark end of arguments for findadv() only
os << "\\endarguments{}"; os << "\\endarguments{}";
} }