- bv->hideCursor();
- bv->update(bv->getLyXText(), BufferView::SELECT | BufferView::FITCUR);
-
- pos_type length;
-
- if (bv->theLockingInset()) {
- bool found = bv->theLockingInset()->nextChange(bv, length);
-
- // We found the stuff inside the inset so we don't have to
- // do anything as the inset did all the update for us!
- if (found)
- return true;
-
- // We now are in the main text but if we did a forward
- // search we have to put the cursor behind the inset.
- bv->text->cursorRight(bv, true);
- }
- // If we arrive here we are in the main text again so we
- // just start searching from the root LyXText at the position
- // we are!
- LyXText * text = bv->text;
-
- if (text->selection.set())
- text->cursor = text->selection.end;
-
- bv->toggleSelection();
- text->clearSelection();
-
- SearchResult result = nextChange(bv, text, length);
-
- lyxerr << "Result is " << result << endl;
-
- bool found = true;
-
- // If we found the cursor inside an inset we will get back
- // SR_FOUND_NOUPDATE and we don't have to do anything as the
- // inset did it already.
- if (result == SR_FOUND) {
- bv->unlockInset(bv->theLockingInset());
- bv->update(text, BufferView::SELECT|BufferView::FITCUR);
- text->setSelectionRange(bv, length);
- bv->toggleSelection(false);
- bv->update(text, BufferView::SELECT|BufferView::FITCUR);
- } else if (result == SR_NOT_FOUND) {
- bv->unlockInset(bv->theLockingInset());
- bv->update(text, BufferView::SELECT|BufferView::FITCUR);
- found = false;
+ DocIterator cur = DocIterator(bv->cursor());
+
+ if (!findChange(cur))
+ return false;
+
+ Paragraph const & par = cur.paragraph();
+ const pos_type pos = cur.pos();
+
+ Change orig_change = par.lookupChangeFull(pos);
+ const pos_type parsize = par.size();
+ pos_type end = pos;
+
+ for (; end != parsize; ++end) {
+ Change change = par.lookupChangeFull(end);
+ if (change != orig_change) {
+ // slight UI optimisation: for replacements, we get
+ // text like : _old_new. Consider that as one change.
+ if (!(orig_change.type == Change::DELETED &&
+ change.type == Change::INSERTED))
+ break;
+ }