X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfind.cpp;h=bb53c35854739da4d9138dd7785bcdb38430b352;hb=9337d73f1f9a6d4dae2e239e9f679a7452660c40;hp=14760d0e333e132a8c2c302a9b00752413a879f0;hpb=0fcae6cc10640f2d5a591152d59d252bb6dc0757;p=lyx.git diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 14760d0e33..bb53c35854 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -16,31 +16,29 @@ #include "lyxfind.h" #include "Buffer.h" +#include "BufferParams.h" #include "Cursor.h" #include "CutAndPaste.h" #include "buffer_funcs.h" #include "BufferView.h" -#include "debug.h" +#include "Changes.h" #include "FuncRequest.h" -#include "gettext.h" #include "Text.h" #include "Paragraph.h" #include "ParIterator.h" -#include "Undo.h" #include "frontends/alert.h" #include "support/convert.h" +#include "support/debug.h" #include "support/docstream.h" +#include "support/gettext.h" +#include "support/lstrings.h" -namespace lyx { - -using support::compare_no_case; -using support::uppercase; -using support::split; - -using std::advance; +using namespace std; +using namespace lyx::support; +namespace lyx { namespace { @@ -54,7 +52,7 @@ bool parse_bool(docstring & howto) } -class MatchString : public std::binary_function +class MatchString : public binary_function { public: MatchString(docstring const & str, bool cs, bool mw) @@ -65,33 +63,7 @@ public: // 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; - pos_type const parsize = par.size(); - for (i = 0; pos + i < parsize; ++i) { - if (docstring::size_type(i) >= size) - break; - if (cs && str[i] != par.getChar(pos + i)) - 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)) - return false; - - // if necessary, check whether string matches word - if (mw) { - if (pos > 0 && par.isLetter(pos - 1)) - return false; - if (pos + pos_type(size) < parsize - && par.isLetter(pos + size)) - return false; - } - - return true; + return par.find(str, cs, mw, pos, del); } private: @@ -137,19 +109,18 @@ bool findChange(DocIterator & cur) } -bool searchAllowed(BufferView * bv, docstring const & str) +bool searchAllowed(BufferView * /*bv*/, docstring const & str) { if (str.empty()) { - frontend::Alert::error(_("Search error"), - _("Search string is empty")); + frontend::Alert::error(_("Search error"), _("Search string is empty")); return false; } return true; } -bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool fw, - bool find_del = true) +bool find(BufferView * bv, docstring const & searchstr, + bool cs, bool mw, bool fw, bool find_del = true) { if (!searchAllowed(bv, searchstr)) return false; @@ -177,7 +148,7 @@ int replaceAll(BufferView * bv, if (!searchAllowed(bv, searchstr) || buf.isReadonly()) return 0; - recordUndoFullDocument(bv); + bv->cursor().recordUndoFullDocument(); MatchString const match(searchstr, cs, mw); int num = 0; @@ -237,7 +208,8 @@ int replace(BufferView * bv, docstring const & searchstr, cap::replaceSelectionWithString(cur, replacestr, fw); bv->buffer().markDirty(); find(bv, searchstr, cs, mw, fw, false); - bv->update(); + bv->buffer().updateMacros(); + bv->processUpdateFlags(Update::Force | Update::FitCursor); return 1; } @@ -272,12 +244,12 @@ docstring const replace2string(docstring const & search, docstring const & repla } -void find(BufferView * bv, FuncRequest const & ev) +bool find(BufferView * bv, FuncRequest const & ev) { if (!bv || ev.action != LFUN_WORD_FIND) - return; + return false; - //lyxerr << "find called, cmd: " << ev << std::endl; + //lyxerr << "find called, cmd: " << ev << endl; // data is of the form // " @@ -289,12 +261,7 @@ void find(BufferView * bv, FuncRequest const & ev) bool matchword = parse_bool(howto); bool forward = parse_bool(howto); - bool const found = find(bv, search, - casesensitive, matchword, forward); - - if (!found) - // emit message signal. - bv->message(_("String not found!")); + return find(bv, search, casesensitive, matchword, forward); } @@ -340,11 +307,9 @@ void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted) } 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. + if (find(bv, search, casesensitive, matchword, forward)) + bv->showCursor(); + else bv->message(_("String not found!")); } }