]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
add the background image to distribution tarball
[lyx.git] / src / lyxfind.cpp
index 59dcb8ff48287a26fb4720b2fe67d9a562e550ec..ca43d47e92b0ac708d550bce79a0f140822022ac 100644 (file)
@@ -232,7 +232,9 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
                if (!cur.inTexted())
                        // bail in math
                        return make_pair(false, 0);
-               // select current word and treat it as the search string
+               // select current word and treat it as the search string.
+               // 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);
        }
@@ -417,21 +419,24 @@ bool findChange(BufferView * bv, bool next)
        // of this function). This will avoid changes to be selected half.
        bool search_both_sides = false;
        Cursor tmpcur = cur;
-       // Leave math first
+       // Find enclosing text cursor
        while (tmpcur.inMathed())
                tmpcur.pop_back();
        Change change_next_pos
                = tmpcur.paragraph().lookupChange(tmpcur.pos());
-       if (change_next_pos.changed() && cur.inMathed()) {
-               cur = tmpcur;
-               search_both_sides = true;
-       } else if (tmpcur.pos() > 0 && tmpcur.inTexted()) {
-               Change change_prev_pos
-                       = tmpcur.paragraph().lookupChange(tmpcur.pos() - 1);
-               if (change_next_pos.isSimilarTo(change_prev_pos))
+       if (change_next_pos.changed()) {
+               if (cur.inMathed()) {
+                       cur = tmpcur;
                        search_both_sides = true;
+               } else if (tmpcur.pos() > 0 && tmpcur.inTexted()) {
+                       Change change_prev_pos
+                               = tmpcur.paragraph().lookupChange(tmpcur.pos() - 1);
+                       if (change_next_pos.isSimilarTo(change_prev_pos))
+                               search_both_sides = true;
+               }
        }
 
+       // find the next change
        if (!findChange(cur, next))
                return false;
 
@@ -439,7 +444,7 @@ bool findChange(BufferView * bv, bool next)
 
        CursorSlice & tip = cur.top();
 
-       if (!next)
+       if (!next && tip.pos() > 0)
                // take a step into the change
                tip.backwardPos();
 
@@ -904,6 +909,9 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
 
 int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) const
 {
+       if (at_begin &&
+               (opt.restr == FindAndReplaceOptions::R_ONLY_MATHS && !cur.inMathed()) )
+               return 0;
        docstring docstr = stringifyFromForSearch(opt, cur, len);
        LYXERR(Debug::FIND, "Matching against     '" << lyx::to_utf8(docstr) << "'");
        string str = normalize(docstr, true);
@@ -1296,10 +1304,10 @@ FindAndReplaceOptions::FindAndReplaceOptions(
        docstring const & find_buf_name, bool casesensitive,
        bool matchword, bool forward, bool expandmacros, bool ignoreformat,
        docstring const & repl_buf_name, bool keep_case,
-       SearchScope scope)
+       SearchScope scope, SearchRestriction restr)
        : find_buf_name(find_buf_name), casesensitive(casesensitive), matchword(matchword),
          forward(forward), expandmacros(expandmacros), ignoreformat(ignoreformat),
-         repl_buf_name(repl_buf_name), keep_case(keep_case), scope(scope)
+         repl_buf_name(repl_buf_name), keep_case(keep_case), scope(scope), restr(restr)
 {
 }
 
@@ -1492,7 +1500,8 @@ ostringstream & operator<<(ostringstream & os, FindAndReplaceOptions const & opt
           << opt.ignoreformat << ' '
           << to_utf8(opt.repl_buf_name) << "\nEOSS\n"
           << opt.keep_case << ' '
-          << int(opt.scope);
+          << int(opt.scope) << ' '
+          << int(opt.restr);
 
        LYXERR(Debug::FIND, "built: " << os.str());
 
@@ -1534,8 +1543,12 @@ istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt)
        int i;
        is >> i;
        opt.scope = FindAndReplaceOptions::SearchScope(i);
+       is >> i;
+       opt.restr = FindAndReplaceOptions::SearchRestriction(i);
+
        LYXERR(Debug::FIND, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' '
-              << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case);
+              << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case << ' '
+              << opt.scope << ' ' << opt.restr);
        return is;
 }