]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
tex2lyx/text.cpp: whitespace fix
[lyx.git] / src / lyxfind.cpp
index af27be2b91861d4a953ad410999a150d5b58c79a..73f6469754fe43b3ca2e903e6c893fac52491622 100644 (file)
@@ -271,7 +271,7 @@ pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
        if (bv->buffer().isReadonly())
                return pair<bool, int>(false, 0);
 
-       cap::replaceSelectionWithString(cur, replacestr, forward);
+       cap::replaceSelectionWithString(cur, replacestr);
        if (forward) {
                cur.pos() += replacestr.length();
                LASSERT(cur.pos() <= cur.lastpos(), /* */);
@@ -565,26 +565,6 @@ string apply_escapes(string s, Escapes const & escape_map)
        return s;
 }
 
-/** Return the position of the closing brace matching the open one at s[pos],
- ** or s.size() if not found.
- **/
-static size_t find_matching_brace(string const & s, size_t pos)
-{
-       LASSERT(s[pos] == '{', /* */);
-       int open_braces = 1;
-       for (++pos; pos < s.size(); ++pos) {
-               if (s[pos] == '\\')
-                       ++pos;
-               else if (s[pos] == '{')
-                       ++open_braces;
-               else if (s[pos] == '}') {
-                       --open_braces;
-                       if (open_braces == 0)
-                               return pos;
-               }
-       }
-       return s.size();
-}
 
 /// Within \regexp{} apply get_lyx_unescapes() only (i.e., preserve regexp semantics of the string),
 /// while outside apply get_lyx_unescapes()+get_regexp_escapes().
@@ -607,7 +587,8 @@ string escape_for_regex(string s, bool match_latex)
                LYXERR(Debug::FIND, "new_pos: " << new_pos);
                if (new_pos == s.size())
                        break;
-               size_t end_pos = s.find("\\endregexp{}}", new_pos + 8); // find_matching_brace(s, new_pos + 7);
+               // Might fail if \\endregexp{} is preceeded by unexpected stuff (weird escapes)
+               size_t end_pos = s.find("\\endregexp{}}", new_pos + 8);
                LYXERR(Debug::FIND, "end_pos: " << end_pos);
                t = s.substr(new_pos + 8, end_pos - (new_pos + 8));
                LYXERR(Debug::FIND, "t in regexp      : " << t);
@@ -1152,12 +1133,12 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
 {
        if (!cur)
                return 0;
-       while (cur) {
+       while (!theApp()->longOperationCancelled() && cur) {
                LYXERR(Debug::FIND, "findForwardAdv() cur: " << cur);
                int match_len = match(cur, -1, false);
                LYXERR(Debug::FIND, "match_len: " << match_len);
                if (match_len) {
-                       for (; cur; cur.forwardPos()) {
+                       for (; !theApp()->longOperationCancelled() && cur; cur.forwardPos()) {
                                LYXERR(Debug::FIND, "Advancing cur: " << cur);
                                int match_len = match(cur);
                                LYXERR(Debug::FIND, "match_len: " << match_len);
@@ -1254,7 +1235,7 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) {
                else
                        cur.backwardPos();
                pit_changed = true;
-       } while (true);
+       } while (!theApp()->longOperationCancelled());
        return 0;
 }
 
@@ -1367,7 +1348,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                }
        }
        cap::cutSelection(cur, false, false);
-       if (!cur.inMathed()) {
+       if (cur.inTexted()) {
                repl_buffer.changeLanguage(
                        repl_buffer.language(),
                        cur.getFont().language());
@@ -1378,7 +1359,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                                        bv->buffer().errorList("Paste"));
                LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
                sel_len = repl_buffer.paragraphs().begin()->size();
-       } else {
+       } else if (cur.inMathed()) {
                TexRow texrow;
                odocstringstream ods;
                otexstream os(ods, texrow);