]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
adjust
[lyx.git] / src / lyxfind.cpp
index aa28e0d83670bbb47654a4d2bb8a6915655a4f8e..81f9a6f1adac2ac48ff0e19c470be036f07abff0 100644 (file)
@@ -144,7 +144,7 @@ bool searchAllowed(BufferView * bv, docstring const & str)
                                            _("Search string is empty"));
                return false;
        }
-       return bv->buffer();
+       return true;
 }
 
 
@@ -172,7 +172,7 @@ int replaceAll(BufferView * bv,
               docstring const & searchstr, docstring const & replacestr,
               bool cs, bool mw)
 {
-       Buffer & buf = *bv->buffer();
+       Buffer & buf = bv->buffer();
 
        if (!searchAllowed(bv, searchstr) || buf.isReadonly())
                return 0;
@@ -227,7 +227,7 @@ bool stringSelected(BufferView * bv, docstring const & searchstr,
 int replace(BufferView * bv, docstring const & searchstr,
            docstring const & replacestr, bool cs, bool mw, bool fw)
 {
-       if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
+       if (!searchAllowed(bv, searchstr) || bv->buffer().isReadonly())
                return 0;
 
        if (!stringSelected(bv, searchstr, cs, mw, fw))
@@ -235,9 +235,9 @@ int replace(BufferView * bv, docstring const & searchstr,
 
        Cursor & cur = bv->cursor();
        cap::replaceSelectionWithString(cur, replacestr, fw);
-       bv->buffer()->markDirty();
+       bv->buffer().markDirty();
        find(bv, searchstr, cs, mw, fw, false);
-       bv->update();
+       bv->processUpdateFlags(Update::Force | Update::FitCursor);
 
        return 1;
 }
@@ -317,25 +317,24 @@ void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted)
        bool all           = parse_bool(howto);
        bool forward       = parse_bool(howto);
 
-       Buffer * buf = bv->buffer();
-
        if (!has_deleted) {
                int const replace_count = all
                        ? replaceAll(bv, search, rplc, casesensitive, matchword)
                        : replace(bv, search, rplc, casesensitive, matchword, forward);
        
+               Buffer & buf = bv->buffer();
                if (replace_count == 0) {
                        // emit message signal.
-                       buf->message(_("String not found!"));
+                       buf.message(_("String not found!"));
                } else {
                        if (replace_count == 1) {
                                // emit message signal.
-                               buf->message(_("String has been replaced."));
+                               buf.message(_("String has been replaced."));
                        } else {
                                docstring str = convert<docstring>(replace_count);
                                str += _(" strings have been replaced.");
                                // emit message signal.
-                               buf->message(str);
+                               buf.message(str);
                        }
                }
        } else {
@@ -353,9 +352,6 @@ void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted)
 
 bool findNextChange(BufferView * bv)
 {
-       if (!bv->buffer())
-               return false;
-
        DocIterator cur = bv->cursor();
 
        if (!findChange(cur))
@@ -366,21 +362,16 @@ bool findNextChange(BufferView * bv)
 
        Change orig_change = cur.paragraph().lookupChange(cur.pos());
 
-       DocIterator et = doc_iterator_end(cur.inset());
-       DocIterator ok = cur;   // see below
-       for (; cur != et; cur.forwardPosNoDescend()) {
-               ok = cur;
-               Change change = cur.paragraph().lookupChange(cur.pos());
-               if (change != orig_change) {
+       CursorSlice & tip = cur.top();
+       for (; !tip.at_end(); tip.forwardPos()) {
+               Change change = tip.paragraph().lookupChange(tip.pos());
+               if (change != orig_change)
                        break;
-               }
        }
-
        // avoid crash (assertion violation) if the imaginary end-of-par
        // character of the last paragraph of the document is marked as changed
-       if (cur == et) {
-               cur = ok;
-       }
+       if (tip.at_end())
+               tip.backwardPos();
 
        // Now put cursor to end of selection:
        bv->cursor().setCursor(cur);