if (!searchAllowed(bv, searchstr) || buf.isReadonly())
return 0;
+ DocIterator cur_orig(bv->cursor());
+
MatchString const match(searchstr, cs, mw);
int num = 0;
bv->putSelectionAt(doc_iterator_begin(&buf), 0, false);
if (num)
buf.markDirty();
+
+ cur_orig.fixIfBroken();
+ bv->setCursor(cur_orig);
+
return num;
}
bool find(BufferView * bv, FuncRequest const & ev)
{
- if (!bv || ev.action != LFUN_WORD_FIND)
+ if (!bv || ev.action() != LFUN_WORD_FIND)
return false;
//lyxerr << "find called, cmd: " << ev << endl;
void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted)
{
- if (!bv || ev.action != LFUN_WORD_REPLACE)
+ if (!bv || ev.action() != LFUN_WORD_REPLACE)
return;
// data is of the form
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()))
+ if (next != (bv->cursor().top() > bv->cursor().normalAnchor()))
bv->cursor().setCursorToAnchor();
}
/// Find the most backward consecutive match within same paragraph while searching backwards.
-void findMostBackwards(DocIterator & cur, MatchStringAdv const & match, int & len)
+int findMostBackwards(DocIterator & cur, MatchStringAdv const & match)
{
DocIterator cur_begin = doc_iterator_begin(cur.buffer());
DocIterator tmp_cur = cur;
- len = findAdvFinalize(tmp_cur, match);
+ int len = findAdvFinalize(tmp_cur, match);
Inset & inset = cur.inset();
for (; cur != cur_begin; cur.backwardPos()) {
LYXERR(Debug::FIND, "findMostBackwards(): cur=" << cur);
len = new_len;
}
LYXERR(Debug::FIND, "findMostBackwards(): exiting with cur=" << cur);
+ return len;
}
found_match = match(cur);
LYXERR(Debug::FIND, "findBackAdv3: found_match="
<< found_match << ", cur: " << cur);
- if (found_match) {
- int len;
- findMostBackwards(cur, match, len);
- return len;
- }
+ if (found_match)
+ return findMostBackwards(cur, match);
+
// Stop if begin of document reached
if (cur == cur_begin)
break;