]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
Continue to improve GtkLengthEntry
[lyx.git] / src / lyxfind.C
index cfee2c9f04435a7be031677ef35ef4764c07eef2..2f16fd3d6ce1dd27ef31f39009a68675d4d4bdf7 100644 (file)
 #include "frontends/Alert.h"
 #include "frontends/LyXView.h"
 
-#include "support/textutils.h"
-#include "support/tostr.h"
+#include "support/convert.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;
@@ -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;
                }
 
@@ -117,9 +116,11 @@ bool findForward(DocIterator & cur, MatchString const & match)
 
 bool findBackwards(DocIterator & cur, MatchString const & match)
 {
-       for (; cur; cur.backwardChar())
+       while (cur) {
+               cur.backwardChar();
                if (cur.inTexted() && match(cur.paragraph(), cur.pos()))
                        return true;
+       }
        return false;
 }
 
@@ -127,7 +128,7 @@ bool findBackwards(DocIterator & cur, MatchString const & match)
 bool findChange(DocIterator & cur)
 {
        for (; cur; cur.forwardChar())
-               if (cur.inTexted() && !cur.paragraph().empty() &&
+               if (cur.inTexted() && cur.pos() != cur.paragraph().size() &&
                    cur.paragraph().lookupChange(cur.pos())
                    != Change::UNCHANGED)
                        return true;
@@ -172,7 +173,7 @@ int replaceAll(BufferView * bv,
        if (!searchAllowed(bv, searchstr) || buf.isReadonly())
                return 0;
 
-       recordUndoFullDocument(bv->cursor());
+       recordUndoFullDocument(bv);
 
        MatchString const match(searchstr, cs, mw);
        int num = 0;
@@ -217,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;
@@ -325,7 +326,7 @@ void replace(BufferView * bv, FuncRequest const & ev)
                if (replace_count == 1) {
                        lv->message(_("String has been replaced."));
                } else {
-                       string str = tostr(replace_count);
+                       string str = convert<string>(replace_count);
                        str += _(" strings have been replaced.");
                        lv->message(str);
                }
@@ -338,16 +339,16 @@ bool findNextChange(BufferView * bv)
        if (!bv->available())
                return false;
 
-       DocIterator cur = DocIterator(bv->cursor());
+       DocIterator cur = 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) {
@@ -361,7 +362,11 @@ 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;
 }