X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfind.cpp;h=6f6d0d53c937dcaa7905623b41a9c94237ce8396;hb=eea4ef9b6e8c103b8d77fb456214a116c68f58a7;hp=45cbbd96f6c12df151b919a8129a663871e5aa39;hpb=8acbcebf117c99ce7d087b4c96401017a488ae57;p=lyx.git diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 45cbbd96f6..6f6d0d53c9 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -93,7 +93,7 @@ class IgnoreFormats { /// bool getLanguage() { return ignoreLanguage_; }; /// - void setIgnoreFormat(string type, bool value); + void setIgnoreFormat(string const & type, bool value); private: /// @@ -119,7 +119,7 @@ private: }; -void IgnoreFormats::setIgnoreFormat(string type, bool value) +void IgnoreFormats::setIgnoreFormat(string const & type, bool value) { if (type == "color") { ignoreColor_ = value; @@ -160,7 +160,7 @@ void IgnoreFormats::setIgnoreFormat(string type, bool value) IgnoreFormats ignoreFormats; -void setIgnoreFormat(string type, bool value) +void setIgnoreFormat(string const & type, bool value) { ignoreFormats.setIgnoreFormat(type, value); } @@ -181,8 +181,8 @@ bool parse_bool(docstring & howto) class MatchString : public binary_function { public: - MatchString(docstring const & str, bool cs, bool mw) - : str(str), case_sens(cs), whole_words(mw) + MatchString(docstring const & s, bool cs, bool mw) + : str(s), case_sens(cs), whole_words(mw) {} // returns true if the specified string is at the specified position @@ -1114,8 +1114,8 @@ class Intervall { bool isPatternString_; public: explicit Intervall(bool isPattern, string const & p) : - isPatternString_(isPattern), par(p), ignoreidx(-1), actualdeptindex(0), - hasTitle(false) + isPatternString_(isPattern), par(p), ignoreidx(-1), actualdeptindex(0), + hasTitle(false), langcount(0) { depts[0] = 0; closes[0] = 0; @@ -1139,6 +1139,7 @@ public: int findclosing(int start, int end, char up, char down, int repeat); void handleParentheses(int lastpos, bool closingAllowed); bool hasTitle; + int langcount; // Number of disabled language specs up to current position in actual interval int isOpeningPar(int pos); string titleValue; void output(ostringstream &os, int lastpos); @@ -1478,7 +1479,8 @@ class LatexInfo { void removeHead(KeyInfo&, int count=0); public: - LatexInfo(string par, bool isPatternString) : entidx_(-1), interval_(isPatternString, par) + LatexInfo(string const & par, bool isPatternString) + : entidx_(-1), interval_(isPatternString, par) { buildKeys(isPatternString); entries_ = vector(); @@ -1554,7 +1556,6 @@ int Intervall::findclosing(int start, int end, char up = '{', char down = '}', i { int skip = 0; int depth = 0; - repeat--; for (int i = start; i < end; i += 1 + skip) { char c; c = par[i]; @@ -1565,6 +1566,7 @@ int Intervall::findclosing(int start, int end, char up = '{', char down = '}', i } else if (c == down) { if (depth == 0) { + repeat--; if ((repeat <= 0) || (par[i+1] != up)) return i; } @@ -1588,7 +1590,7 @@ class MathInfo { MathInfo() { actualIdx_ = 0; } - void insert(string wait, size_t start, size_t end) { + void insert(string const & wait, size_t start, size_t end) { MathEntry m = MathEntry(); m.wait = wait; m.mathStart = start; @@ -1905,10 +1907,20 @@ void LatexInfo::buildEntries(bool isPatternString) } found._tokensize = found.head.length(); found._dataStart = found._tokenstart + found.head.length(); + if (found.keytype == KeyInfo::doRemove) { + int endpar = 2 + interval_.findclosing(found._dataStart, interval_.par.length(), '{', '}', closings); + found._dataStart = endpar; + found._tokensize = found._dataStart - found._tokenstart; + closings = 0; + } if (interval_.par.substr(found._dataStart-1, 15).compare("\\endarguments{}") == 0) { found._dataStart += 15; } - size_t endpos = interval_.findclosing(found._dataStart, interval_.par.length(), '{', '}', closings); + size_t endpos; + if (closings < 1) + endpos = found._dataStart - 1; + else + endpos = interval_.findclosing(found._dataStart, interval_.par.length(), '{', '}', closings); if (found.keytype == KeyInfo::isList) { // Check if it really is list env static regex const listre("^([a-z]+)$"); @@ -2032,6 +2044,11 @@ void LatexInfo::buildKeys(bool isPatternString) // handle like standard keys with 1 parameter. makeKey("url|href|vref|thanks", KeyInfo(KeyInfo::isStandard, 1, false), isPatternString); + // Ignore deleted text + makeKey("lyxdeleted", KeyInfo(KeyInfo::doRemove, 3, false), isPatternString); + // but preserve added text + makeKey("lyxadded", KeyInfo(KeyInfo::doRemove, 2, false), isPatternString); + // Macros to remove, but let the parameter survive // No split makeKey("menuitem|textmd|textrm", KeyInfo(KeyInfo::isStandard, 1, true), isPatternString); @@ -2173,7 +2190,12 @@ void Intervall::output(ostringstream &os, int lastpos) printed += lastpos-i; } handleParentheses(lastpos, false); - for (int i = actualdeptindex; i > 0; --i) { + int startindex; + if (keys["foreignlanguage"].disabled) + startindex = actualdeptindex-langcount; + else + startindex = actualdeptindex; + for (int i = startindex; i > 0; --i) { os << "}"; } if (hasTitle && (printed > 0)) @@ -2328,7 +2350,23 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual) if ((interval_.par[pos] != ' ') && (interval_.par[pos] != '%')) break; } - interval_.addIntervall(actual._tokenstart, pos); + // Remove also enclosing parentheses [] and {} + int numpars = 0; + int spaces = 0; + while (actual._tokenstart > numpars) { + if (interval_.par[pos+numpars] == ']' && interval_.par[actual._tokenstart-numpars-1] == '[') + numpars++; + else if (interval_.par[pos+numpars] == '}' && interval_.par[actual._tokenstart-numpars-1] == '{') + numpars++; + else + break; + } + if (numpars > 0) { + if (interval_.par[pos+numpars] == ' ') + spaces++; + } + + interval_.addIntervall(actual._tokenstart-numpars, pos+numpars+spaces); nextKeyIdx = getNextKey(); break; } @@ -2435,6 +2473,7 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual) } if (actual.disabled) { removeHead(actual); + interval_.langcount++; if ((interval_.par.substr(actual._dataStart, 3) == " \\[") || (interval_.par.substr(actual._dataStart, 8) == " \\begin{")) { // Discard also the space before math-equation @@ -2924,9 +2963,9 @@ MatchResult MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_be if (m.size() > 1) leadingsize = m[1].second - m[1].first; int result; - for (size_t i = 0; i < m.size(); i++) { - LYXERR(Debug::FIND, "Match " << i << " is " << m[i].second - m[i].first << " long"); - } + for (size_t i = 0; i < m.size(); i++) { + LYXERR(Debug::FIND, "Match " << i << " is " << m[i].second - m[i].first << " long"); + } if (close_wildcards == 0) result = m[0].second - m[0].first; @@ -2991,9 +3030,9 @@ MatchResult MatchStringAdv::operator()(DocIterator const & cur, int len, bool at << ", inTexted=" << cur.inTexted()); if (res == 0 || !at_begin || !opt.matchword || !cur.inTexted()) return mres; - if ((len > 0) && (res < len)) { + if ((len > 0) && (res < len)) { mres.match_len = 0; - return mres; + return mres; } Paragraph const & par = cur.paragraph(); bool ws_left = (cur.pos() > 0) @@ -3005,18 +3044,18 @@ MatchResult MatchStringAdv::operator()(DocIterator const & cur, int len, bool at LYXERR(Debug::FIND, "cur.pos()=" << cur.pos() << ", res=" << res << ", separ: " << ws_left << ", " << ws_right - << ", len: " << len + << ", len: " << len << endl); if (ws_left && ws_right) { - // Check for word separators inside the found 'word' - for (int i = 0; i < len; i++) { - if (par.isWordSeparator(cur.pos() + i)) { + // Check for word separators inside the found 'word' + for (int i = 0; i < len; i++) { + if (par.isWordSeparator(cur.pos() + i)) { mres.match_len = 0; - return mres; + return mres; } - } - return mres; - } + } + return mres; + } mres.match_len = 0; return mres; } @@ -3378,10 +3417,9 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) match_len_zero_count = 0; } else { - if (++match_len_zero_count > 3) { - LYXERR(Debug::FIND, "match_len2_zero_count: " << match_len_zero_count << ", match_len was " << match_len); - match_len_zero_count = 0; - } + if (++match_len_zero_count > 3) { + LYXERR(Debug::FIND, "match_len2_zero_count: " << match_len_zero_count << ", match_len was " << match_len); + } break; } } @@ -3490,13 +3528,13 @@ docstring stringifyFromForSearch(FindAndReplaceOptions const & opt, 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, SearchRestriction restr, bool replace_all) - : 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), restr(restr), replace_all(replace_all) + 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, SearchRestriction _restr, bool _replace_all) + : 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), restr(_restr), replace_all(_replace_all) { }