X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfind.cpp;h=aa28e0d83670bbb47654a4d2bb8a6915655a4f8e;hb=8524ee93c35ed3ca15a0aaafa7b893f2f7d21f47;hp=ebfa51968efea1932cfca8600e280e38cecc198a;hpb=897436efbb9bd641b61467d185a2dfae9839e575;p=lyx.git diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index ebfa51968e..aa28e0d836 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -62,7 +62,8 @@ public: {} // returns true if the specified string is at the specified position - bool operator()(Paragraph const & par, pos_type pos) const + // del specifies whether deleted strings in ct mode will be considered + bool operator()(Paragraph const & par, pos_type pos, bool del = true) const { docstring::size_type const size = str.length(); pos_type i = 0; @@ -74,6 +75,8 @@ public: break; if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i))) break; + if (!del && par.isDeleted(pos + i)) + break; } if (size != docstring::size_type(i)) @@ -101,20 +104,24 @@ private: }; -bool findForward(DocIterator & cur, MatchString const & match) +bool findForward(DocIterator & cur, MatchString const & match, + bool find_del = true) { for (; cur; cur.forwardChar()) - if (cur.inTexted() && match(cur.paragraph(), cur.pos())) + if (cur.inTexted() && + match(cur.paragraph(), cur.pos(), find_del)) return true; return false; } -bool findBackwards(DocIterator & cur, MatchString const & match) +bool findBackwards(DocIterator & cur, MatchString const & match, + bool find_del = true) { while (cur) { cur.backwardChar(); - if (cur.inTexted() && match(cur.paragraph(), cur.pos())) + if (cur.inTexted() && + match(cur.paragraph(), cur.pos(), find_del)) return true; } return false; @@ -141,7 +148,8 @@ bool searchAllowed(BufferView * bv, docstring const & str) } -bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool fw) +bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool fw, + bool find_del = true) { if (!searchAllowed(bv, searchstr)) return false; @@ -150,7 +158,8 @@ bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool f MatchString const match(searchstr, cs, mw); - bool found = fw ? findForward(cur, match) : findBackwards(cur, match); + bool found = fw ? findForward(cur, match, find_del) : + findBackwards(cur, match, find_del); if (found) bv->putSelectionAt(cur, searchstr.length(), !fw); @@ -177,7 +186,7 @@ int replaceAll(BufferView * bv, int const ssize = searchstr.size(); DocIterator cur = doc_iterator_begin(buf.inset()); - while (findForward(cur, match)) { + while (findForward(cur, match, false)) { pos_type pos = cur.pos(); Font const font = cur.paragraph().getFontSettings(buf.params(), pos); @@ -227,7 +236,7 @@ int replace(BufferView * bv, docstring const & searchstr, Cursor & cur = bv->cursor(); cap::replaceSelectionWithString(cur, replacestr, fw); bv->buffer()->markDirty(); - find(bv, searchstr, cs, mw, fw); + find(bv, searchstr, cs, mw, fw, false); bv->update(); return 1; @@ -289,7 +298,7 @@ void find(BufferView * bv, FuncRequest const & ev) } -void replace(BufferView * bv, FuncRequest const & ev) +void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted) { if (!bv || ev.action != LFUN_WORD_REPLACE) return; @@ -310,23 +319,34 @@ void replace(BufferView * bv, FuncRequest const & ev) Buffer * buf = bv->buffer(); - int const replace_count = all - ? replaceAll(bv, search, rplc, casesensitive, matchword) - : replace(bv, search, rplc, casesensitive, matchword, forward); - - if (replace_count == 0) { - // emit message signal. - buf->message(_("String not found!")); - } else { - if (replace_count == 1) { + if (!has_deleted) { + int const replace_count = all + ? replaceAll(bv, search, rplc, casesensitive, matchword) + : replace(bv, search, rplc, casesensitive, matchword, forward); + + if (replace_count == 0) { // emit message signal. - buf->message(_("String has been replaced.")); + buf->message(_("String not found!")); } else { - docstring str = convert(replace_count); - str += _(" strings have been replaced."); - // emit message signal. - buf->message(str); + if (replace_count == 1) { + // emit message signal. + buf->message(_("String has been replaced.")); + } else { + docstring str = convert(replace_count); + str += _(" strings have been replaced."); + // emit message signal. + buf->message(str); + } } + } else { + // if we have deleted characters, we do not replace at all, but + // rather search for the next occurence + bool const found = find(bv, search, + casesensitive, matchword, forward); + + if (!found) + // emit message signal. + bv->message(_("String not found!")); } }