Fixed issues in backward search in various corner cases (fixed #6482 and #6596).

Now, when scope includes multiple documents, the switch_buffer LFUN is only issues if buffer actually changes.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33812 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Tommaso Cucinotta 2010-03-20 13:59:46 +00:00
parent 83104beee3
commit 57aa866a1c
2 changed files with 29 additions and 31 deletions

View File

@ -355,7 +355,7 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt)
Buffer * buf = &bv->buffer();
Buffer * buf_orig = &bv->buffer();
Cursor cur_orig(bv->cursor());
DocIterator cur_orig(bv->cursor());
if (opt.scope == FindAndReplaceOptions::S_ALL_MANUALS) {
vector<string> const & v = allManualsFiles();
@ -378,6 +378,7 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt)
do {
LYXERR(Debug::FIND, "Dispatching LFUN_WORD_FINDADV");
dispatch(cmd);
LYXERR(Debug::FIND, "dispatched");
if (bv->cursor().result().dispatched()) {
// Match found, selected and replaced if needed
return;
@ -396,6 +397,7 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt)
if (wrap_answer == 1)
break;
}
if (buf != &view_.documentBufferView()->buffer())
lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
buf->absFileName()));
bv = view_.documentBufferView();
@ -403,7 +405,7 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt)
bv->cursor().clear();
bv->cursor().push_back(CursorSlice(buf->inset()));
} else {
lyx::dispatch(FuncRequest(LFUN_BUFFER_END));
//lyx::dispatch(FuncRequest(LFUN_BUFFER_END));
bv->cursor().setCursor(doc_iterator_end(buf));
bv->cursor().backwardPos();
LYXERR(Debug::FIND, "findBackAdv5: cur: "
@ -411,11 +413,11 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt)
}
bv->clearSelection();
} while (wrap_answer != 1);
if (buf != buf_orig)
if (buf_orig != &view_.documentBufferView()->buffer())
lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
buf_orig->absFileName()));
bv = view_.documentBufferView();
bv->cursor() = cur_orig;
bv->cursor().setCursor(cur_orig);
}

View File

@ -980,25 +980,21 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
void findMostBackwards(DocIterator & cur, MatchStringAdv const & match, int & len)
{
DocIterator cur_begin = doc_iterator_begin(cur.buffer());
len = findAdvFinalize(cur, match);
if (cur != cur_begin) {
DocIterator tmp_cur = cur;
len = findAdvFinalize(tmp_cur, match);
Inset & inset = cur.inset();
int old_len;
DocIterator old_cur;
DocIterator dit2;
do {
old_cur = cur;
old_len = len;
cur.backwardPos();
LYXERR(Debug::FIND, "findMostBackwards(): old_cur="
<< old_cur << ", old_len=" << len << ", cur=" << cur);
dit2 = cur;
} while (cur != cur_begin && &cur.inset() == &inset && match(cur)
&& (len = findAdvFinalize(dit2, match)) > old_len);
cur = old_cur;
len = old_len;
}
for (; cur != cur_begin; cur.backwardPos()) {
LYXERR(Debug::FIND, "findMostBackwards(): cur=" << cur);
DocIterator new_cur = cur;
new_cur.backwardPos();
if (new_cur == cur || &new_cur.inset() != &inset || !match(new_cur))
break;
int new_len = findAdvFinalize(new_cur, match);
if (new_len == len)
break;
len = new_len;
}
LYXERR(Debug::FIND, "findMostBackwards(): exiting with cur=" << cur);
}
@ -1007,10 +1003,11 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) {
if (! cur)
return 0;
// Backup of original position
DocIterator cur_orig(cur);
DocIterator cur_begin = doc_iterator_begin(cur.buffer());
if (cur == cur_begin)
return 0;
cur.backwardPos();
DocIterator cur_orig(cur);
bool found_match;
bool pit_changed = false;
found_match = false;
@ -1025,22 +1022,21 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) {
cur.pos() = cur_orig.pos();
LYXERR(Debug::FIND, "findBackAdv2: cur: " << cur);
DocIterator cur_prev_iter;
while (true) {
do {
found_match = match(cur);
LYXERR(Debug::FIND, "findBackAdv3: found_match="
<< found_match << ", cur: " << cur);
if (found_match) {
int len;
findMostBackwards(cur, match, len);
if (cur < cur_orig)
return len;
}
// Prevent infinite loop at begin of document
if (cur == cur_begin || cur == cur_prev_iter)
// Stop if begin of document reached
if (cur == cur_begin)
break;
cur_prev_iter = cur;
cur.backwardPos();
}
} while (true);
}
if (cur == cur_begin)
break;