]> git.lyx.org Git - features.git/commitdiff
Amend 7ac04a2b: Count and display number of replaced strings in FindAdv
authorKornel Benko <kornel@lyx.org>
Sat, 16 Mar 2019 07:17:09 +0000 (08:17 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:16 +0000 (15:48 +0200)
We have to know if the previous call to search was a single replace or not,
so that we can correctly initialize the numer of replaed strings.

src/lyxfind.cpp

index 0d7d539d1bebf563a6f382082c7dff890a0a80a6..a6c9f4dd76ef6902dfb9283c71127da2642c3dc1 100644 (file)
@@ -2639,6 +2639,7 @@ static int identifyClosing(string & t)
 }
 
 static int num_replaced = 0;
+static bool previous_single_replace = true;
 
 MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & opt)
        : p_buf(&buf), p_first_buf(&buf), opt(opt)
@@ -2646,8 +2647,14 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
        Buffer & find_buf = *theBufferList().getBuffer(FileName(to_utf8(opt.find_buf_name)), true);
        docstring const & ds = stringifySearchBuffer(find_buf, opt);
        use_regexp = lyx::to_utf8(ds).find("\\regexp{") != std::string::npos;
-       if (!opt.replace_all)
+       if (opt.replace_all && previous_single_replace) {
+               previous_single_replace = false;
+               num_replaced = 0;
+       }
+       else if (!opt.replace_all) {
                num_replaced = 0;       // count number of replaced strings
+               previous_single_replace = true;
+       }
        // When using regexp, braces are hacked already by escape_for_regex()
        par_as_string = normalize(ds, !use_regexp);
        open_braces = 0;