]> git.lyx.org Git - lyx.git/commitdiff
FindAdv: If possible use unicode instead of math command when searching
authorKornel Benko <kornel@lyx.org>
Sun, 20 Mar 2022 10:33:12 +0000 (11:33 +0100)
committerKornel Benko <kornel@lyx.org>
Sun, 20 Mar 2022 10:33:12 +0000 (11:33 +0100)
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

src/lyxfind.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathNest.cpp
src/mathed/MathExtern.cpp
src/mathed/MathStream.h

index c187e1060291093d51409366b20f352fe787ca25..98c254da1e995bcbe0c5dc71a8d1a2f684d5faf3 100644 (file)
@@ -917,7 +917,7 @@ string escape_for_regex(string s, bool withformat)
                        if (lastpos == s.size())
                                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);
                lastpos = end_pos + 13;
        }
@@ -3519,6 +3519,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt)
                string lead_as_regexp;
                if (lead_size > 0) {
                        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, "}$", "");
                        par_as_string = par_as_string_nolead;
                        LYXERR(Debug::FIND, "lead_as_regexp is '" << lead_as_regexp << "'");
index 8b63c73f8d2afa328cad722b4ac5148b0f8d5d20..805f84c47932a7b8f8b2599de66337a22c0517dd 100644 (file)
@@ -2357,12 +2357,19 @@ int InsetMathHull::plaintext(odocstringstream & os,
        odocstringstream oss;
        otexrowstream ots(oss);
        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
-       if (type_ == hullRegexp)
+       if (type_ == hullRegexp) {
+               TeXMathStream wi(ots, false, true, ot, enc);
                write(wi);
+       }
        else {
+               TeXMathStream wi(ots, false, true, ot, enc);
                for (row_type r = 0; r < nrows(); ++r) {
                        for (col_type c = 0; c < ncols(); ++c)
                                wi << (c == 0 ? "" : "\t") << cell(index(r, c));
index 7241e0bc3bd4e065f7e64bf886731938ce5cc8a6..4f21924a815a7d74cbdb2e16e621de46361cf21c 100644 (file)
@@ -358,8 +358,14 @@ void InsetMathNest::normalize(NormalStream & os) const
 
 void InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const
 {
-       TeXMathStream wi(os, runparams.moving_arg, true,
-                        runparams.dryrun ? TeXMathStream::wsDryrun : TeXMathStream::wsDefault,
+       TeXMathStream::OutputType ot;
+       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);
        wi.strikeoutMath(runparams.inDeletedInset);
        if (runparams.inulemcmd) {
index 5c182c719fc98be3af8edc13e9d30bcdce45fe4c..527543a33b8b4aeeb9ea69cfd399ebaee380b753 100644 (file)
@@ -1425,6 +1425,10 @@ void writeString(docstring const & s, TeXMathStream & os)
                os << (os.asciiOnly() ? escape(s) : s);
                return;
        }
+       else if (os.output() == TeXMathStream::wsSearchAdv) {
+               os << s;
+               return;
+       }
 
        if (os.lockedMode()) {
                bool space;
index d6a35c5e89f64476e5fbffcf1fb4b83d11452854..6d0399e4c8e2bca0b902caf2c16de4f4505a613d 100644 (file)
@@ -38,7 +38,8 @@ public:
        enum OutputType {
                wsDefault,
                wsDryrun,
-               wsPreview
+               wsPreview,
+               wsSearchAdv
        };
        ///
        enum UlemCmdType {