diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 91402c3396..afa8a9b30f 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -426,6 +426,12 @@ void Cursor::resetAnchor() } +void Cursor::setCursorToAnchor() +{ + if (selection()) + setCursor(anchor_); +} + bool Cursor::posBackward() { diff --git a/src/Cursor.h b/src/Cursor.h index 276bf2e989..81b2d9b97e 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -63,6 +63,8 @@ public: void leaveInset(Inset const & inset); /// sets cursor part void setCursor(DocIterator const & it); + /// sets the cursor to the anchor + void setCursorToAnchor(); /// void setCurrentFont(); diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 40e503e5f9..6fa6aade1f 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -352,6 +352,13 @@ 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(); if (!findChange(cur, next)) return false;