]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Part of r32942. We want to avoid reload flickering when
[lyx.git] / src / lyxfind.cpp
index bf99caf33f536244fb1315d73eeea7b95a7c8eeb..d65936e6232814e9d15f5ef40e4f7373e97cead2 100644 (file)
 #include "lyxfind.h"
 
 #include "Buffer.h"
-#include "BufferList.h"
 #include "buffer_funcs.h"
+#include "BufferList.h"
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Changes.h"
 #include "Cursor.h"
 #include "CutAndPaste.h"
 #include "FuncRequest.h"
-#include "OutputParams.h"
+#include "LyXFunc.h"
 #include "output_latex.h"
+#include "OutputParams.h"
 #include "Paragraph.h"
 #include "ParIterator.h"
 #include "TexRow.h"
 #include "Text.h"
-#include "FuncRequest.h"
-#include "LyXFunc.h"
+
+#include "frontends/alert.h"
 
 #include "mathed/InsetMath.h"
 #include "mathed/InsetMathGrid.h"
 #include "mathed/InsetMathHull.h"
 #include "mathed/MathStream.h"
 
-#include "frontends/alert.h"
-
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
-#include "support/lstrings.h"
 #include "support/lassert.h"
-
-#include "frontends/Application.h"
-#include "frontends/LyXView.h"
+#include "support/lstrings.h"
 
 #include <boost/regex.hpp>
 #include <boost/next_prior.hpp>
@@ -635,6 +631,9 @@ public:
        FindAndReplaceOptions const & opt;
 
 private:
+       /// Auxiliary find method (does not account for opt.matchword)
+       int findAux(DocIterator const & cur, int len = -1, bool at_begin = true) const;
+
        /** Normalize a stringified or latexified LyX paragraph.
         **
         ** Normalize means:
@@ -722,7 +721,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
 }
 
 
-int MatchStringAdv::operator()(DocIterator const & cur, int len, bool at_begin) const
+int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) const
 {
        docstring docstr = stringifyFromForSearch(opt, cur, len);
        LYXERR(Debug::FIND, "Matching against     '" << lyx::to_utf8(docstr) << "'");
@@ -765,6 +764,26 @@ int MatchStringAdv::operator()(DocIterator const & cur, int len, bool at_begin)
 }
 
 
+int MatchStringAdv::operator()(DocIterator const & cur, int len, bool at_begin) const
+{
+       int res = findAux(cur, len, at_begin);
+       if (res == 0 || !at_begin || !opt.matchword || !cur.inTexted())
+               return res;
+       Paragraph const & par = cur.paragraph();
+       bool ws_left = cur.pos() > 0 ?
+               par.isWordSeparator(cur.pos() - 1) : true;
+       bool ws_right = cur.pos() + res < par.size() ?
+               par.isWordSeparator(cur.pos() + res) : true;
+       LYXERR(Debug::FIND,
+              "cur.pos()=" << cur.pos() << ", res=" << res
+              << ", separ: " << ws_left << ", " << ws_right
+              << endl);
+       if (ws_left && ws_right)
+               return res;
+       return 0;
+}
+
+
 string MatchStringAdv::normalize(docstring const & s) const
 {
        string t;
@@ -1203,7 +1222,7 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt)
 }
 
 
-ostringstream & operator<<(ostringstream & os, lyx::FindAndReplaceOptions const & opt)
+ostringstream & operator<<(ostringstream & os, FindAndReplaceOptions const & opt)
 {
        os << to_utf8(opt.search) << "\nEOSS\n"
           << opt.casesensitive << ' '
@@ -1221,7 +1240,7 @@ ostringstream & operator<<(ostringstream & os, lyx::FindAndReplaceOptions const
        return os;
 }
 
-istringstream & operator>>(istringstream & is, lyx::FindAndReplaceOptions & opt)
+istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt)
 {
        LYXERR(Debug::FIND, "parsing");
        string s;