commit 04bf5583b903f4d96edf2de83420beab835fb425
Author: Kornel Benko <kor...@lyx.org>
Date:   Sat Jul 19 19:25:16 2025 +0200

    Moved  check for wrapped search to BufferView
    
    Fixes #13200
---
 src/BufferView.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------
 src/lyxfind.cpp    | 40 +++------------------------------------
 2 files changed, 50 insertions(+), 45 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index a7a5ad93ea..38e71d0792 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1942,14 +1942,53 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
                FindAndReplaceOptions opt;
                istringstream iss(to_utf8(cmd.argument()));
                iss >> opt;
-               if (findAdv(this, opt)) {
-                       dr.screenUpdate(Update::Force | Update::FitCursor);
-                       cur.dispatched();
-                       dispatched = true;
-               } else {
-                       cur.undispatched();
-                       dispatched = false;
-               }
+               bool repeat_search;
+               do {
+                       repeat_search = false;
+
+                       if (findAdv(this, opt)) {
+                               dr.screenUpdate(Update::Force | 
Update::FitCursor);
+                               cur.dispatched();
+                               dispatched = true;
+                       } else {
+                               DocIterator cur_orig(cursor());
+                               if (opt.forward) {
+                                       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) {
+                                               cursor().clear();
+                                               
cursor().push_back(CursorSlice(buffer().inset()));
+                                               repeat_search =  true;
+                                       }
+                               }
+                               else {
+                                       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) {
+                                               
cursor().setCursor(doc_iterator_end(&buffer()));
+                                               cursor().backwardPos();
+                                               dispatched = true;
+                                               repeat_search =  true;
+                                       }
+                               }
+
+                               if (repeat_search)  {
+                                       clearSelection();
+                                       
cur.setCursor(cursor().selectionBegin());
+                                       dr.screenUpdate(Update::Force | 
Update::FitCursor);
+                                       cur.dispatched();
+                                       dispatched = true;
+                               }
+                               else {
+                                       cur.undispatched();
+                                       dispatched = false;
+                               }
+                       }
+               } while (repeat_search);
                break;
        }
 
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index df71e12532..be65634519 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -697,57 +697,23 @@ bool lyxreplace(BufferView * bv, FuncRequest const & ev)
 }
 
 
-bool findNextChange(BufferView * bv, Cursor & cur, bool const check_wrap)
+bool findNextChange(Cursor & cur)
 {
        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(BufferView * bv, Cursor & cur, bool const check_wrap)
+bool findPreviousChange(Cursor & cur)
 {
        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;
 }
 
@@ -792,7 +758,7 @@ bool findChange(BufferView * bv, bool forward)
        Cursor cur(*bv);
        cur.setCursor(forward ? bv->cursor().selectionEnd()
                      : bv->cursor().selectionBegin());
-       forward ? findNextChange(bv, cur, true) : findPreviousChange(bv, cur, 
true);
+       forward ? findNextChange(cur) : findPreviousChange(cur);
        return selectChange(cur, forward);
 }
 
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to