From 0be77e2eb2a9bc599c99219ebe80f27be7537bd5 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 15 Oct 2016 16:34:16 +0200 Subject: [PATCH] Implement wrapping in next-change (#10388). --- src/lyxfind.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- status.22x | 2 ++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 4d2da98c9b..d26b1c89b6 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -417,21 +417,57 @@ bool lyxreplace(BufferView * bv, } -bool findNextChange(DocIterator & cur) +bool findNextChange(BufferView * bv, Cursor & cur, bool const check_wrap) { for (; cur; cur.forwardPos()) if (cur.inTexted() && cur.paragraph().isChanged(cur.pos())) return true; + + if (check_wrap) { + DocIterator cur_orig(bv->cursor()); + docstring q = _("End of file reached while searching forward.\n" + "Continue searching from the beginning?"); + int wrap_answer = frontend::Alert::prompt(_("Wrap search?"), + q, 0, 1, _("&Yes"), _("&No")); + if (wrap_answer == 0) { + bv->cursor().clear(); + bv->cursor().push_back(CursorSlice(bv->buffer().inset())); + bv->clearSelection(); + cur.setCursor(bv->cursor().selectionBegin()); + if (findNextChange(bv, cur, false)) + return true; + } + bv->cursor().setCursor(cur_orig); + } + return false; } -bool findPreviousChange(DocIterator & cur) +bool findPreviousChange(BufferView * bv, Cursor & cur, bool const check_wrap) { for (cur.backwardPos(); cur; cur.backwardPos()) { if (cur.inTexted() && cur.paragraph().isChanged(cur.pos())) return true; } + + if (check_wrap) { + DocIterator cur_orig(bv->cursor()); + docstring q = _("Beginning of file reached while searching backward.\n" + "Continue searching from the end?"); + int wrap_answer = frontend::Alert::prompt(_("Wrap search?"), + q, 0, 1, _("&Yes"), _("&No")); + if (wrap_answer == 0) { + bv->cursor().setCursor(doc_iterator_end(&bv->buffer())); + bv->cursor().backwardPos(); + bv->clearSelection(); + cur.setCursor(bv->cursor().selectionBegin()); + if (findPreviousChange(bv, cur, false)) + return true; + } + bv->cursor().setCursor(cur_orig); + } + return false; } @@ -476,7 +512,7 @@ bool findChange(BufferView * bv, bool forward) Cursor cur(*bv); cur.setCursor(forward ? bv->cursor().selectionEnd() : bv->cursor().selectionBegin()); - forward ? findNextChange(cur) : findPreviousChange(cur); + forward ? findNextChange(bv, cur, true) : findPreviousChange(bv, cur, true); return selectChange(cur, forward); } diff --git a/status.22x b/status.22x index 6e38d469e0..783cb6a05b 100644 --- a/status.22x +++ b/status.22x @@ -31,6 +31,8 @@ What's new - Improve cross-references dialog design. +- Implement wrap-around in change tracking's next-change function (bug 10388). + * DOCUMENTATION AND LOCALIZATION