]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Prevent warning when pressing OKAY while the dialog is in AUTOAPPLY_INITIAL state...
[lyx.git] / src / lyxfind.cpp
index 40e503e5f9d8a0a83c76c242ee431e7978a6bd43..efbd00b223b3acfbf5a18b6ba7cc3d2782b71860 100644 (file)
@@ -352,7 +352,28 @@ bool findPreviousChange(BufferView * bv)
 
 bool findChange(BufferView * bv, bool next)
 {
+       if (bv->cursor().selection()) {
+               // set the cursor at the beginning or at the end of the selection
+               // before searching. Otherwise, the current change will be found.
+               if (next != bv->cursor().top() > bv->cursor().anchor())
+                       bv->cursor().setCursorToAnchor();
+       }
+
        DocIterator cur = bv->cursor();
+       
+       // Are we within a change ? Then first search forward (backward), 
+       // clear the selection and search the other way around (see the end
+       // of this function). This will avoid changes to be selected half.
+       bool search_both_sides = false;
+       if (cur.pos() > 1) {
+               Change change_next_pos  
+                       = cur.paragraph().lookupChange(cur.pos());
+               Change change_prev_pos 
+                       = cur.paragraph().lookupChange(cur.pos() - 1);
+               if (change_next_pos.isSimilarTo(change_prev_pos))
+                       search_both_sides = true;
+       }
+
        if (!findChange(cur, next))
                return false;
 
@@ -373,7 +394,8 @@ bool findChange(BufferView * bv, bool next)
                                break;
                }
        } else {
-               for (; !tip.at_begin(); tip.backwardPos()) {
+               for (; !tip.at_begin();) {
+                       tip.backwardPos();
                        Change change = tip.paragraph().lookupChange(tip.pos());
                        if (change != orig_change) {
                                // take a step forward to correctly set the selection
@@ -387,6 +409,11 @@ bool findChange(BufferView * bv, bool next)
        bv->cursor().setCursor(cur);
        bv->cursor().setSelection();
 
+       if (search_both_sides) {
+               bv->cursor().setSelection(false);
+               findChange(bv, !next);
+       }
+
        return true;
 }