Fix bug #2213 (part 1): GuiChanges lacks "Previous Change" button.

*lyxfind: Add findPreviousChange().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29108 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-04-05 19:11:25 +00:00
parent b5880744c9
commit 5a1dc72483
2 changed files with 50 additions and 9 deletions

View File

@ -115,11 +115,19 @@ bool findBackwards(DocIterator & cur, MatchString const & match,
} }
bool findChange(DocIterator & cur) bool findChange(DocIterator & cur, bool next)
{ {
for (; cur; cur.forwardPos()) if (!next)
if (cur.inTexted() && !cur.paragraph().isUnchanged(cur.pos())) cur.backwardPos();
for (; cur; next ? cur.forwardPos() : cur.backwardPos())
if (cur.inTexted() && !cur.paragraph().isUnchanged(cur.pos())) {
if (!next)
// if we search backwards, take a step forward
// to correctly set the anchor
cur.forwardPos();
return true; return true;
}
return false; return false;
} }
@ -332,21 +340,47 @@ void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted)
bool findNextChange(BufferView * bv) bool findNextChange(BufferView * bv)
{ {
DocIterator cur = bv->cursor(); return findChange(bv, true);
}
if (!findChange(cur))
bool findPreviousChange(BufferView * bv)
{
return findChange(bv, false);
}
bool findChange(BufferView * bv, bool next)
{
DocIterator cur = bv->cursor();
if (!findChange(cur, next))
return false; return false;
bv->cursor().setCursor(cur); bv->cursor().setCursor(cur);
bv->cursor().resetAnchor(); bv->cursor().resetAnchor();
if (!next)
// take a step into the change
cur.backwardPos();
Change orig_change = cur.paragraph().lookupChange(cur.pos()); Change orig_change = cur.paragraph().lookupChange(cur.pos());
CursorSlice & tip = cur.top(); CursorSlice & tip = cur.top();
for (; !tip.at_end(); tip.forwardPos()) { if (next) {
Change change = tip.paragraph().lookupChange(tip.pos()); for (; !tip.at_end(); tip.forwardPos()) {
if (change != orig_change) Change change = tip.paragraph().lookupChange(tip.pos());
break; if (change != orig_change)
break;
}
} else {
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
tip.forwardPos();
break;
}
}
} }
// Now put cursor to end of selection: // Now put cursor to end of selection:

View File

@ -66,6 +66,13 @@ void replace(BufferView * bv, FuncRequest const &, bool has_deleted = false);
/// find the next change in the buffer /// find the next change in the buffer
bool findNextChange(BufferView * bv); bool findNextChange(BufferView * bv);
/// find the previous change in the buffer
bool findPreviousChange(BufferView * bv);
/// find the change in the buffer
/// \param next true to find the next change, otherwise the previous
bool findChange(BufferView * bv, bool next);
// Hopefully, nobody will ever replace with something like this // Hopefully, nobody will ever replace with something like this
#define LYX_FR_NULL_STRING "__LYX__F&R__NULL__STRING__" #define LYX_FR_NULL_STRING "__LYX__F&R__NULL__STRING__"