commit 1b2a56e2d24f47d5240d96d952b3d2ecb8716126
Author: Juergen Spitzmueller <[email protected]>
Date:   Tue Jan 12 16:13:47 2021 +0100

    Ignore tracked deletions in simple replace (#11194)
---
 src/BufferView.cpp |   15 +------------
 src/lyxfind.cpp    |   60 +++++++++++++++++++++------------------------------
 src/lyxfind.h      |    3 +-
 3 files changed, 27 insertions(+), 51 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 6735808..d0ce7e1 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1653,20 +1653,7 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr)
        }
 
        case LFUN_WORD_REPLACE: {
-               bool has_deleted = false;
-               if (cur.selection()) {
-                       DocIterator beg = cur.selectionBegin();
-                       DocIterator end = cur.selectionEnd();
-                       if (beg.pit() == end.pit()) {
-                               for (pos_type p = beg.pos() ; p < end.pos() ; 
++p) {
-                                       if (!cur.inMathed() && 
cur.paragraph().isDeleted(p)) {
-                                               has_deleted = true;
-                                               break;
-                                       }
-                               }
-                       }
-               }
-               if (lyxreplace(this, cmd, has_deleted)) {
+               if (lyxreplace(this, cmd)) {
                        dr.forceBufferUpdate();
                        dr.screenUpdate(Update::Force | Update::FitCursor);
                }
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 677b382..34a352d 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -376,7 +376,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring 
searchstr,
                // This causes a minor bug as undo will restore this selection,
                // which the user did not create (#8986).
                cur.innerText()->selectWord(cur, WHOLE_WORD);
-               searchstr = cur.selectionAsString(false);
+               searchstr = cur.selectionAsString(false, true);
        }
 
        // if we still don't have a search string, report the error
@@ -385,7 +385,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring 
searchstr,
                return make_pair(false, 0);
 
        bool have_selection = cur.selection();
-       docstring const selected = cur.selectionAsString(false);
+       docstring const selected = cur.selectionAsString(false, true);
        bool match =
                case_sens
                ? searchstr == selected
@@ -468,8 +468,7 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev)
 }
 
 
-bool lyxreplace(BufferView * bv,
-               FuncRequest const & ev, bool has_deleted)
+bool lyxreplace(BufferView * bv, FuncRequest const & ev)
 {
        if (!bv || ev.action() != LFUN_WORD_REPLACE)
                return false;
@@ -491,40 +490,31 @@ bool lyxreplace(BufferView * bv,
 
        bool update = false;
 
-       if (!has_deleted) {
-               int replace_count = 0;
-               if (all) {
-                       replace_count = replaceAll(bv, search, rplc, 
casesensitive, matchword);
-                       update = replace_count > 0;
-               } else {
-                       pair<bool, int> rv =
-                               replaceOne(bv, search, rplc, casesensitive, 
matchword, forward, findnext);
-                       update = rv.first;
-                       replace_count = rv.second;
-               }
+       int replace_count = 0;
+       if (all) {
+               replace_count = replaceAll(bv, search, rplc, casesensitive, 
matchword);
+               update = replace_count > 0;
+       } else {
+               pair<bool, int> rv =
+                       replaceOne(bv, search, rplc, casesensitive, matchword, 
forward, findnext);
+               update = rv.first;
+               replace_count = rv.second;
+       }
 
-               Buffer const & buf = bv->buffer();
-               if (!update) {
-                       // emit message signal.
-                       buf.message(_("String not found."));
+       Buffer const & buf = bv->buffer();
+       if (!update) {
+               // emit message signal.
+               buf.message(_("String not found."));
+       } else {
+               if (replace_count == 0) {
+                       buf.message(_("String found."));
+               } else if (replace_count == 1) {
+                       buf.message(_("String has been replaced."));
                } else {
-                       if (replace_count == 0) {
-                               buf.message(_("String found."));
-                       } else if (replace_count == 1) {
-                               buf.message(_("String has been replaced."));
-                       } else {
-                               docstring const str =
-                                       bformat(_("%1$d strings have been 
replaced."), replace_count);
-                               buf.message(str);
-                       }
+                       docstring const str =
+                               bformat(_("%1$d strings have been replaced."), 
replace_count);
+                       buf.message(str);
                }
-       } else if (findnext) {
-               // if we have deleted characters, we do not replace at all, but
-               // rather search for the next occurence
-               if (findOne(bv, search, casesensitive, matchword, forward, 
true, findnext))
-                       update = true;
-               else
-                       bv->message(_("String not found."));
        }
        return update;
 }
diff --git a/src/lyxfind.h b/src/lyxfind.h
index deb31b2..a5454f1 100644
--- a/src/lyxfind.h
+++ b/src/lyxfind.h
@@ -60,8 +60,7 @@ bool lyxfind(BufferView * bv, FuncRequest const & ev);
  * The string is encoded by \c replace2string.
  * \return whether we did anything
  */
-bool lyxreplace(BufferView * bv,
-               FuncRequest const &, bool has_deleted = false);
+bool lyxreplace(BufferView * bv, FuncRequest const &);
 
 /// find the next change in the buffer
 bool findNextChange(BufferView * bv);
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to