commit 441b0eab2370b8b6cbe0c0a75a1718405a4b6329
Author: Kornel Benko <[email protected]>
Date:   Sun May 8 22:43:56 2022 +0200

    FindAdv: Amend 64af721a
    
    The space handling is a nightmare.
---
 src/Paragraph.cpp         |    3 +++
 src/insets/InsetSpace.cpp |    8 ++++++--
 src/lyxfind.cpp           |   25 ++++++++++++++++++-------
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index e1ece12..7357337 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1223,6 +1223,9 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
                        case '}':
                                os << "\\braceright ";
                                return;
+                       case '~':
+                               os << "\\lyxtilde ";
+                               return;
                        case ' ':
                        case '\0':
                                break;
diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp
index 669239b..ffcc8b5 100644
--- a/src/insets/InsetSpace.cpp
+++ b/src/insets/InsetSpace.cpp
@@ -679,7 +679,7 @@ void InsetSpace::latex(otexstream & os, OutputParams const 
& runparams) const
 
 
 int InsetSpace::plaintext(odocstringstream & os,
-        OutputParams const &, size_t) const
+        OutputParams const &runparams, size_t) const
 {
        switch (params_.kind) {
        case InsetSpaceParams::HFILL:
@@ -737,7 +737,11 @@ int InsetSpace::plaintext(odocstringstream & os,
                return 1;
        case InsetSpaceParams::PROTECTED:
        case InsetSpaceParams::CUSTOM_PROTECTED:
-               os.put(0x00a0);
+               if (runparams.for_search == OutputParams::NoSearch)
+                       os.put(0x00a0);
+               else {
+                       os.put(' ');
+               }
                return 1;
        case InsetSpaceParams::NEGTHIN:
        case InsetSpaceParams::NEGMEDIUM:
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 9c70938..4df0f1e 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -833,14 +833,20 @@ string string2regex(string in)
                }
                else {
                        if (blanks > 0) {
-                               temp += "\\s+";
+                               if (blanks > 1)
+                                       temp += "\\s+";
+                               else
+                                       temp += "\\s";
                        }
                        temp += tempx[i];
                        blanks = 0;
                }
        }
        if (blanks > 0) {
-               temp += "\\s+";
+               if (blanks > 1)
+                       temp += "\\s+";
+               else
+                       temp += "\\s";
        }
 
        string temp2("");
@@ -1161,7 +1167,7 @@ static docstring buffer_to_latex(Buffer & buffer)
        return ods.str();
 }
 
-static string latexNamesToUtf8(docstring strIn)
+static string latexNamesToUtf8(docstring strIn, bool withformat)
 {
        string addtmp = to_utf8(strIn);
        static regex const rmAcc("(\\\\)*("
@@ -1203,6 +1209,10 @@ static string latexNamesToUtf8(docstring strIn)
                add = addtmp;
        else if (addtmp.length() > lastpos)
                add += addtmp.substr(lastpos, addtmp.length() - lastpos);
+       if (!withformat) {
+               static std::regex repltilde { R"(~)" };
+               add = std::regex_replace(add, repltilde, accents["lyxtilde"]);
+       }
        LYXERR(Debug::FINDVERBOSE, "Adding to search string: '"
                        << add << "'");
        return add;
@@ -1234,7 +1244,7 @@ static docstring stringifySearchBuffer(Buffer & buffer, 
FindAndReplaceOptions co
                        Paragraph const & par = buffer.paragraphs().at(pit);
                        string add = latexNamesToUtf8(par.asString(pos_type(0), 
par.size(),
                                                                option,
-                                                               &runparams));
+                                                               &runparams), 
!opt.ignoreformat);
                        LYXERR(Debug::FINDVERBOSE, "Adding to search string: '"
                                << add << "'");
                        t += add;
@@ -1929,7 +1939,6 @@ static void buildAccentsMap()
        accents["cdot"] = "·";
        accents["textasciicircum"] = "^";
        accents["mathcircumflex"] = "^";
-       accents["sim"] = "~";
        accents["guillemotright"] = "»";
        accents["guillemotleft"] = "«";
        accents["hairspace"]     = getutf8(0xf0000);    // select from free 
unicode plane 15
@@ -1950,6 +1959,8 @@ static void buildAccentsMap()
        accents["lyxarrow"]      = getutf8(0xf0020);
        accents["braceleft"]     = getutf8(0xf0030);
        accents["braceright"]    = getutf8(0xf0031);
+       accents["lyxtilde"]      = getutf8(0xf0032);
+       accents["sim"]           = getutf8(0xf0032);
        accents["backslash lyx"]           = getutf8(0xf0010);  // Used logos 
inserted with starting \backslash
        accents["backslash LyX"]           = getutf8(0xf0010);
        accents["backslash tex"]           = getutf8(0xf0011);
@@ -4015,7 +4026,7 @@ docstring stringifyFromCursor(DocIterator const & cur, 
int len)
                       << cur << ", from pos: " << cur.pos() << ", end: " << 
end);
                docstring res = 
from_utf8(latexNamesToUtf8(par.asString(cur.pos(), end,
                                                                        option,
-                                                                       
&runparams)));
+                                                                       
&runparams), false));
                LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Stringified text from 
pos(" << cur.pos() << ") len(" << len << "): " << res);
                return res;
        } else if (cur.inMathed()) {
@@ -4028,7 +4039,7 @@ docstring stringifyFromCursor(DocIterator const & cur, 
int len)
                MathData md2;
                for (MathData::const_iterator it = md.begin() + cs.pos(); it != 
it_end; ++it)
                        md2.push_back(*it);
-               docstring res = from_utf8(latexNamesToUtf8(asString(md2)));
+               docstring res = from_utf8(latexNamesToUtf8(asString(md2), 
false));
                LYXERR(Debug::FINDVERBOSE|Debug::FIND, "Stringified math from 
pos(" << cur.pos() << ") len(" << len << "): " << res);
                return res;
        }
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to