]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
more cursor dispatch
[lyx.git] / src / lyxfind.C
index 65d5843b6b57d968a1011946601f18467fe6b5c8..b7869ba32725a8a26681cd2bc73816d7d131064d 100644 (file)
@@ -16,7 +16,7 @@
 #include "lyxfind.h"
 
 #include "buffer.h"
-#include "cursor_slice.h"
+#include "cursor.h"
 #include "BufferView.h"
 #include "debug.h"
 #include "iterators.h"
@@ -39,6 +39,7 @@ using lyx::support::lowercase;
 using lyx::support::uppercase;
 using lyx::support::split;
 
+using std::advance;
 using std::ostringstream;
 using std::string;
 
@@ -78,7 +79,7 @@ namespace lyx {
 namespace find {
 
 string const find2string(string const & search,
-                        bool casesensitive, bool matchword, bool forward)
+                        bool casesensitive, bool matchword, bool forward)
 {
        ostringstream ss;
        ss << search << '\n'
@@ -88,7 +89,7 @@ string const find2string(string const & search,
 
        return ss.str();
 }
+
 
 string const replace2string(string const & search, string const & replace,
                            bool casesensitive, bool matchword,
@@ -122,7 +123,7 @@ void find(BufferView * bv, FuncRequest const & ev)
        bool forward       = parse_bool(howto);
 
        bool const found = ::find(bv, search,
-                                 forward, casesensitive, matchword);
+                                 casesensitive, matchword, forward);
 
        if (!found)
                bv->owner()->message(_("String not found!"));
@@ -155,7 +156,7 @@ void replace(BufferView * bv, FuncRequest const & ev)
                             casesensitive, matchword) :
                ::replace(bv, search, replace,
                          casesensitive, matchword, forward);
+
        if (replace_count == 0) {
                lv->message(_("String not found!"));
        } else {
@@ -180,10 +181,10 @@ bool findNextChange(BufferView * bv)
 
        if (!findChange(cur, endit))
                return false;
-       
+
        ParagraphList::iterator pit = cur.pit();
        pos_type pos = cur.pos();
-       
+
        Change orig_change = pit->lookupChangeFull(pos);
        pos_type parsize = pit->size();
        pos_type end = pos;
@@ -209,7 +210,7 @@ bool findNextChange(BufferView * bv)
 
 namespace {
 
-class MatchString
+class MatchString : public std::binary_function<Paragraph, lyx::pos_type, bool>
 {
 public:
        MatchString(string const & str, bool cs, bool mw)
@@ -243,7 +244,7 @@ public:
 
                return true;
        }
-       
+
 private:
        // search string
        string str;
@@ -280,7 +281,7 @@ bool findBackwards(PosIterator & cur, PosIterator const & beg,
 bool findChange(PosIterator & cur, PosIterator const & end)
 {
        for (; cur != end; ++cur) {
-               if ((!cur.pit()->size() || !cur.at_end())
+               if ((cur.pit()->empty() || !cur.at_end())
                    && cur.pit()->lookupChange(cur.pos()) != Change::UNCHANGED)
                        return true;
        }
@@ -328,9 +329,9 @@ int replaceAll(BufferView * bv,
 
        if (!searchAllowed(bv, searchstr) || buf.isReadonly())
                return 0;
-       
-       recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1);
-       
+
+       recordUndoFullDocument(bv->cursor());
+
        PosIterator cur = buf.pos_iterator_begin();
        PosIterator const end = buf.pos_iterator_end();
        MatchString const match(searchstr, cs, mw);
@@ -359,7 +360,7 @@ int replaceAll(BufferView * bv,
 
 
 bool stringSelected(BufferView * bv,
-                   string const & searchstr, 
+                   string const & searchstr,
                    bool cs, bool mw, bool fw)
 {
        LyXText * text = bv->getLyXText();
@@ -391,11 +392,11 @@ int replace(BufferView * bv,
 
        text->replaceSelectionWithString(replacestr);
        text->setSelectionRange(replacestr.length());
-       bv->cursor() = fw ? bv->selEnd() : bv->selStart();
+       bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin();
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
        bv->update();
-       
+
        return 1;
 }