FindAdv: If possible use unicode instead of math command when searching

Wrong behaviour before this commit:
Open new lyx-file
insert
	unicode-insert 0x025c 0x1d08
Open adv-find dialog
search for unicode 0x025c OK
search for unicode 0x1d08 OK
search with regex for unicode 0x025c OK
search with regex for unicode 0x1d08 ==> NOT OK (because we are searching for \textrevepsilon
	and this was mapped to 0x025c
This commit is contained in:
Kornel Benko 2022-03-20 11:33:12 +01:00
parent 32de59d84a
commit e6d998d33c
5 changed files with 25 additions and 6 deletions

View File

@ -917,7 +917,7 @@ string escape_for_regex(string s, bool withformat)
if (lastpos == s.size()) if (lastpos == s.size())
break; break;
} }
size_t end_pos = s.find("\\endregexp{}}", regex_pos + 8); size_t end_pos = s.find("\\endregexp{", regex_pos + 8);
result += correctRegex(s.substr(regex_pos + 8, end_pos -(regex_pos + 8)), withformat); result += correctRegex(s.substr(regex_pos + 8, end_pos -(regex_pos + 8)), withformat);
lastpos = end_pos + 13; lastpos = end_pos + 13;
} }
@ -3519,6 +3519,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt)
string lead_as_regexp; string lead_as_regexp;
if (lead_size > 0) { if (lead_size > 0) {
lead_as_regexp = string2regex(par_as_string.substr(0, lead_size)); lead_as_regexp = string2regex(par_as_string.substr(0, lead_size));
(void)regex_replace(par_as_string_nolead, par_as_string_nolead, "\\$$", "");
(void)regex_replace(par_as_string_nolead, par_as_string_nolead, "}$", ""); (void)regex_replace(par_as_string_nolead, par_as_string_nolead, "}$", "");
par_as_string = par_as_string_nolead; par_as_string = par_as_string_nolead;
LYXERR(Debug::FIND, "lead_as_regexp is '" << lead_as_regexp << "'"); LYXERR(Debug::FIND, "lead_as_regexp is '" << lead_as_regexp << "'");

View File

@ -2357,12 +2357,19 @@ int InsetMathHull::plaintext(odocstringstream & os,
odocstringstream oss; odocstringstream oss;
otexrowstream ots(oss); otexrowstream ots(oss);
Encoding const * const enc = encodings.fromLyXName("utf8"); Encoding const * const enc = encodings.fromLyXName("utf8");
TeXMathStream wi(ots, false, true, TeXMathStream::wsDefault, enc);
TeXMathStream::OutputType ot;
if (op.for_searchAdv == OutputParams::NoSearch)
ot = TeXMathStream::wsDefault;
else
ot = TeXMathStream::wsSearchAdv;
// Fix Bug #6139 // Fix Bug #6139
if (type_ == hullRegexp) if (type_ == hullRegexp) {
TeXMathStream wi(ots, false, true, ot, enc);
write(wi); write(wi);
}
else { else {
TeXMathStream wi(ots, false, true, ot, enc);
for (row_type r = 0; r < nrows(); ++r) { for (row_type r = 0; r < nrows(); ++r) {
for (col_type c = 0; c < ncols(); ++c) for (col_type c = 0; c < ncols(); ++c)
wi << (c == 0 ? "" : "\t") << cell(index(r, c)); wi << (c == 0 ? "" : "\t") << cell(index(r, c));

View File

@ -358,8 +358,14 @@ void InsetMathNest::normalize(NormalStream & os) const
void InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const void InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const
{ {
TeXMathStream wi(os, runparams.moving_arg, true, TeXMathStream::OutputType ot;
runparams.dryrun ? TeXMathStream::wsDryrun : TeXMathStream::wsDefault, if (runparams.for_searchAdv != OutputParams::NoSearch)
ot = TeXMathStream::wsSearchAdv;
else if (runparams.dryrun)
ot = TeXMathStream::wsDryrun;
else
ot = TeXMathStream::wsDefault;
TeXMathStream wi(os, runparams.moving_arg, true, ot,
runparams.encoding); runparams.encoding);
wi.strikeoutMath(runparams.inDeletedInset); wi.strikeoutMath(runparams.inDeletedInset);
if (runparams.inulemcmd) { if (runparams.inulemcmd) {

View File

@ -1425,6 +1425,10 @@ void writeString(docstring const & s, TeXMathStream & os)
os << (os.asciiOnly() ? escape(s) : s); os << (os.asciiOnly() ? escape(s) : s);
return; return;
} }
else if (os.output() == TeXMathStream::wsSearchAdv) {
os << s;
return;
}
if (os.lockedMode()) { if (os.lockedMode()) {
bool space; bool space;

View File

@ -38,7 +38,8 @@ public:
enum OutputType { enum OutputType {
wsDefault, wsDefault,
wsDryrun, wsDryrun,
wsPreview wsPreview,
wsSearchAdv
}; };
/// ///
enum UlemCmdType { enum UlemCmdType {