]> git.lyx.org Git - features.git/blobdiff - src/lyxfind.cpp
FindAdv: Fix the length of leading string
[features.git] / src / lyxfind.cpp
index 69e740d470e51730008b9fe88a8f89f7582ec868..c0d86409f9c3987ea81e0ed4f7822dc6522f6484 100644 (file)
@@ -1088,6 +1088,15 @@ void MatchStringAdv::FillResults(MatchResult &found_mr)
                valid_matches = 0;
 }
 
+static void setFindParams(OutputParams &runparams)
+{
+       runparams.flavor = Flavor::XeTeX;
+       //runparams.use_polyglossia = true;
+       runparams.linelen = 10000; //lyxrc.plaintext_linelen;
+       // No side effect of file copying and image conversion
+       runparams.dryrun = true;
+}
+
 static docstring buffer_to_latex(Buffer & buffer)
 {
        //OutputParams runparams(&buffer.params().encoding());
@@ -1095,10 +1104,7 @@ static docstring buffer_to_latex(Buffer & buffer)
        odocstringstream ods;
        otexstream os(ods);
        runparams.nice = true;
-       runparams.flavor = Flavor::XeTeX;
-       runparams.linelen = 10000; //lyxrc.plaintext_linelen;
-       // No side effect of file copying and image conversion
-       runparams.dryrun = true;
+       setFindParams(runparams);
        if (ignoreFormats.getDeleted())
                runparams.for_search = OutputParams::SearchWithoutDeleted;
        else
@@ -1108,7 +1114,7 @@ static docstring buffer_to_latex(Buffer & buffer)
        }
        pit_type const endpit = buffer.paragraphs().size();
        for (pit_type pit = 0; pit != endpit; ++pit) {
-               TeXOnePar(buffer, buffer.text(), pit, os, runparams);
+               TeXOnePar(buffer, buffer.text(), pit, os, runparams, string(), -1, -1, true);
                LYXERR(Debug::FINDVERBOSE, "searchString up to here: " << ods.str());
        }
        return ods.str();
@@ -1170,9 +1176,7 @@ static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions co
                // OutputParams runparams(&buffer.params().encoding());
                OutputParams runparams(encodings.fromLyXName("utf8"));
                runparams.nice = true;
-               runparams.flavor = Flavor::XeTeX;
-               runparams.linelen = 10000; //lyxrc.plaintext_linelen;
-               runparams.dryrun = true;
+               setFindParams(runparams);
                int option = AS_STR_INSETS |AS_STR_PLAINTEXT;
                if (ignoreFormats.getDeleted()) {
                        option |= AS_STR_SKIPDELETE;
@@ -1222,7 +1226,7 @@ static size_t identifyLeading(string const & s)
               || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\*?\\}", ""))
               ;
        LYXERR(Debug::FINDVERBOSE, "  after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'");
-       return s.find(t);
+       return s.size() - t.size();
 }
 
 /*
@@ -2750,6 +2754,7 @@ void LatexInfo::buildKeys(bool isPatternString)
        makeKey("triangleuppar|triangledownpar|droppar", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
        makeKey("triangleleftpar|shapepar|dropuppar",    KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
        makeKey("hphantom|vphantom|note|footnote|shortcut|include|includegraphics",     KeyInfo(KeyInfo::isStandard, 1, true), isPatternString);
+       makeKey("textgreek|textcyrillic", KeyInfo(KeyInfo::isStandard, 1, true), false);
        makeKey("parbox", KeyInfo(KeyInfo::doRemove, 1, true), isPatternString);
        // like ('tiny{}' or '\tiny ' ... )
        makeKey("footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge", KeyInfo(KeyInfo::isSize, 0, false), isPatternString);
@@ -3420,24 +3425,23 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with
 
 
 // Remove trailing closure of math, macros and environments, so to catch parts of them.
-static int identifyClosing(string & t)
+static void identifyClosing(string & t, bool ignoreformat)
 {
-       int open_braces = 0;
        do {
                LYXERR(Debug::FINDVERBOSE, "identifyClosing(): t now is '" << t << "'");
                if (regex_replace(t, t, "(.*[^\\\\])\\$$", "$1"))
                        continue;
                if (regex_replace(t, t, "(.*[^\\\\])\\\\\\]$", "$1"))
                        continue;
-               if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]*\\*?\\}$", "$1"))
-                       continue;
-               if (regex_replace(t, t, "(.*[^\\\\])\\}$", "$1")) {
-                       ++open_braces;
+               if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]+\\*?\\}$", "$1"))
                        continue;
+               if (! ignoreformat) {
+                       if (regex_replace(t, t, "(.*[^\\\\])\\}$", "$1"))
+                               continue;
                }
                break;
        } while (true);
-       return open_braces;
+       return;
 }
 
 static int num_replaced = 0;
@@ -3564,7 +3568,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt)
        }
        opt.matchAtStart = false;
        if (!use_regexp) {
-               identifyClosing(par_as_string); // Removes math closings ($, ], ...) at end of string
+               identifyClosing(par_as_string, opt.ignoreformat); // Removes math closings ($, ], ...) at end of string
                if (opt.ignoreformat) {
                        lead_size = 0;
                }
@@ -3942,10 +3946,7 @@ docstring stringifyFromCursor(DocIterator const & cur, int len)
                // OutputParams runparams(&cur.buffer()->params().encoding());
                OutputParams runparams(encodings.fromLyXName("utf8"));
                runparams.nice = true;
-               runparams.flavor = Flavor::XeTeX;
-               runparams.linelen = 10000; //lyxrc.plaintext_linelen;
-               // No side effect of file copying and image conversion
-               runparams.dryrun = true;
+               setFindParams(runparams);
                int option = AS_STR_INSETS | AS_STR_PLAINTEXT;
                if (ignoreFormats.getDeleted()) {
                        option |= AS_STR_SKIPDELETE;
@@ -4000,10 +4001,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
        //OutputParams runparams(&buf.params().encoding());
        OutputParams runparams(encodings.fromLyXName("utf8"));
        runparams.nice = false;
-       runparams.flavor = Flavor::XeTeX;
-       runparams.linelen = 8000; //lyxrc.plaintext_linelen;
-       // No side effect of file copying and image conversion
-       runparams.dryrun = true;
+       setFindParams(runparams);
        if (ignoreFormats.getDeleted()) {
                runparams.for_search = OutputParams::SearchWithoutDeleted;
        }
@@ -4020,7 +4018,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                if (len != -1 && endpos > cur.pos() + len)
                        endpos = cur.pos() + len;
                TeXOnePar(buf, *cur.innerText(), cur.pit(), os, runparams,
-                         string(), cur.pos(), endpos);
+                         string(), cur.pos(), endpos, true);
                LYXERR(Debug::FIND, "Latexified text from pos(" << cur.pos() << ") len(" << len << "): " << ods.str());
                return(ods.str());
        } else if (cur.inMathed()) {
@@ -4610,10 +4608,8 @@ static int findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, Ma
                // OutputParams runparams(&repl_buffer.params().encoding());
                OutputParams runparams(encodings.fromLyXName("utf8"));
                runparams.nice = false;
-               runparams.flavor = Flavor::XeTeX;
-               runparams.linelen = 8000; //lyxrc.plaintext_linelen;
-               runparams.dryrun = true;
-               TeXOnePar(repl_buffer, repl_buffer.text(), 0, os, runparams);
+               setFindParams(runparams);
+               TeXOnePar(repl_buffer, repl_buffer.text(), 0, os, runparams, string(), -1, -1, true);
                //repl_buffer.getSourceCode(ods, 0, repl_buffer.paragraphs().size(), false);
                docstring repl_latex = ods.str();
                LYXERR(Debug::FINDVERBOSE, "Latexified replace_buffer: '" << repl_latex << "'");