]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / lyxfind.C
index ba654484c7e9e4c21a1cf0cf4194053513354486..479d4771167799f20a9197f5167b4bc79b6f7c2a 100644 (file)
 #include "frontends/Alert.h"
 #include "frontends/LyXView.h"
 
-#include "support/textutils.h"
 #include "support/tostr.h"
 
-#include "support/std_sstream.h"
+#include <sstream>
 
 using lyx::support::lowercase;
 using lyx::support::uppercase;
 using lyx::support::split;
 
-using lyx::par_type;
+using lyx::pit_type;
 using lyx::pos_type;
 
 using std::advance;
@@ -75,7 +74,7 @@ public:
                for (i = 0; pos + i < parsize; ++i) {
                        if (string::size_type(i) >= size)
                                break;
-                 if (cs && str[i] != par.getChar(pos + i))
+                       if (cs && str[i] != par.getChar(pos + i))
                                break;
                        if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i)))
                                break;
@@ -86,10 +85,10 @@ public:
 
                // if necessary, check whether string matches word
                if (mw) {
-                       if (pos > 0     && IsLetterCharOrDigit(par.getChar(pos - 1)))
+                       if (pos > 0 && par.isLetter(pos - 1))
                                return false;
                        if (pos + lyx::pos_type(size) < parsize
-                                       && IsLetterCharOrDigit(par.getChar(pos + size)));
+                           && par.isLetter(pos + size));
                                return false;
                }
 
@@ -108,8 +107,8 @@ private:
 
 bool findForward(DocIterator & cur, MatchString const & match)
 {
-       for (; cur.size(); cur.forwardChar())
-               if (match(cur.paragraph(), cur.pos()))
+       for (; cur; cur.forwardChar())
+               if (cur.inTexted() && match(cur.paragraph(), cur.pos()))
                        return true;
        return false;
 }
@@ -117,18 +116,21 @@ bool findForward(DocIterator & cur, MatchString const & match)
 
 bool findBackwards(DocIterator & cur, MatchString const & match)
 {
-       for (; cur.size(); cur.backwardChar())
-               if (match(cur.paragraph(), cur.pos()))
+       while (cur) {
+               cur.backwardChar();
+               if (cur.inTexted() && match(cur.paragraph(), cur.pos()))
                        return true;
+       }
        return false;
 }
 
 
 bool findChange(DocIterator & cur)
 {
-       for (; cur.size(); cur.forwardChar())
-               if ((cur.paragraph().empty() || !cur.empty())
-                   && cur.paragraph().lookupChange(cur.pos()) != Change::UNCHANGED)
+       for (; cur; cur.forwardChar())
+               if (cur.inTexted() && !cur.paragraph().empty() &&
+                   cur.paragraph().lookupChange(cur.pos())
+                   != Change::UNCHANGED)
                        return true;
        return false;
 }
@@ -179,7 +181,7 @@ int replaceAll(BufferView * bv,
        int const rsize = replacestr.size();
        int const ssize = searchstr.size();
 
-       DocIterator cur = DocIterator(buf.inset());
+       DocIterator cur = doc_iterator_begin(buf.inset());
        while (findForward(cur, match)) {
                lyx::pos_type pos = cur.pos();
                LyXFont const font
@@ -192,7 +194,7 @@ int replaceAll(BufferView * bv,
        }
 
        bv->text()->init(bv);
-       bv->putSelectionAt(DocIterator(buf.inset()), 0, false);
+       bv->putSelectionAt(doc_iterator_begin(buf.inset()), 0, false);
        if (num)
                buf.markDirty();
        return num;
@@ -216,7 +218,7 @@ bool stringSelected(BufferView * bv, string const & searchstr,
 
 
 int replace(BufferView * bv, string const & searchstr,
-      string const & replacestr, bool cs, bool mw, bool fw)
+           string const & replacestr, bool cs, bool mw, bool fw)
 {
        if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
                return 0;
@@ -337,16 +339,16 @@ bool findNextChange(BufferView * bv)
        if (!bv->available())
                return false;
 
-       DocIterator cur = DocIterator(bv->buffer()->inset());
+       DocIterator cur = DocIterator(bv->cursor());
 
        if (!findChange(cur))
                return false;
 
        Paragraph const & par = cur.paragraph();
-       pos_type pos = cur.pos();
+       const pos_type pos = cur.pos();
 
        Change orig_change = par.lookupChangeFull(pos);
-       pos_type parsize = par.size();
+       const pos_type parsize = par.size();
        pos_type end = pos;
 
        for (; end != parsize; ++end) {
@@ -360,11 +362,13 @@ bool findNextChange(BufferView * bv)
                }
        }
        pos_type length = end - pos;
-       bv->putSelectionAt(cur, length, true);
+       bv->putSelectionAt(cur, length, false);
+       // if we used a lfun like in find/replace, dispatch would do
+       // that for us
+       bv->update();
+
        return true;
 }
 
 } // find namespace
 } // lyx namespace
-
-