]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Finds formatted matches in the middle of paragraphs, when no regular expressions...
[lyx.git] / src / lyxfind.cpp
index c5adc57dd030b2d431b450b6685756f969b22455..6b9d4d7e5f5fa8fe693efc1a0dc838705925e2bb 100644 (file)
@@ -236,7 +236,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
                // empty search string
                if (!cur.inTexted())
                        // bail in math
-                       return pair<int, bool>(0, false);
+                       return pair<bool, int>(false, 0);
                // select current word and treat it as the search string
                cur.innerText()->selectWord(cur, WHOLE_WORD);
                searchstr = cur.selectionAsString(false);
@@ -766,15 +766,23 @@ int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) con
        string str = normalize(docstr);
        LYXERR(Debug::FIND, "After normalization: '" << str << "'");
        if (! opt.regexp) {
+               LYXERR(Debug::FIND, "Searching in normal mode: par_as_string='" << par_as_string << "', str='" << str << "'");
                if (at_begin) {
+                       LYXERR(Debug::FIND, "size=" << par_as_string.size() << ", substr='" << str.substr(0, par_as_string.size()) << "'");
                        if (str.substr(0, par_as_string.size()) == par_as_string)
                                return par_as_string.size();
                } else {
-                       size_t pos = str.find(par_as_string);
+                       string t = par_as_string;
+                       while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\{", "")
+                              || regex_replace(t, t, "^\\$", "")
+                              || regex_replace(t, t, "^\\\\\\[ ", ""))
+                               LYXERR(Debug::FIND, "  after removing leading $, \[ , \\emph{, \\textbf{, etc.: " << t);
+                       size_t pos = str.find(t);
                        if (pos != string::npos)
                                return par_as_string.size();
                }
        } else {
+               LYXERR(Debug::FIND, "Searching in regexp mode");
                // Try all possible regexp matches, 
                //until one that verifies the braces match test is found
                regex const *p_regexp = at_begin ? &regexp : &regexp2;
@@ -841,7 +849,7 @@ string MatchStringAdv::normalize(docstring const & s) const
                t.replace(pos, 1, " ");
        // Remove stale empty \emph{}, \textbf{} and similar blocks from latexify
        LYXERR(Debug::FIND, "Removing stale empty \\emph{}, \\textbf{}, \\*section{} macros from: " << t);
-       while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph)(\\{\\})+", ""))
+       while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)(\\{\\})+", ""))
                LYXERR(Debug::FIND, "  further removing stale empty \\emph{}, \\textbf{} macros from: " << t);
        return t;
 }
@@ -1220,6 +1228,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
        bv->buffer().markDirty();
        cur.pos() -= repl_buffer.paragraphs().begin()->size();
        bv->putSelectionAt(DocIterator(cur), repl_buffer.paragraphs().begin()->size(), !opt.forward);
+       bv->processUpdateFlags(Update::Force);
 }