Author: tommaso
Date: Fri May 27 22:39:58 2011
New Revision: 38860
URL: http://www.lyx.org/trac/changeset/38860

Log:
Fixed Advanced F&R issue in matching things at environment borders with 
ignore-format off.
Added accompanying regression tests for displayed math and numbered equations.

Added:
   lyx-devel/trunk/development/autotests/findadv-14-in.txt
   lyx-devel/trunk/development/autotests/findadv-15-in.txt
Modified:
   lyx-devel/trunk/src/lyxfind.cpp

Added: lyx-devel/trunk/development/autotests/findadv-14-in.txt
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ lyx-devel/trunk/development/autotests/findadv-14-in.txt     Fri May 27 
22:39:58 2011        (r38860)
@@ -0,0 +1,37 @@
+# Finding displayed maths with ignore-format on&off (might affect #7596)
+#
+Lang it_IT.utf8
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \Axmath-display\[Return]
+KK: x^2 +x^2\C\[Home]
+KK: \Cs
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 2\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \Axmath-display\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 2\n with len: 1' lyx-log.txt

Added: lyx-devel/trunk/development/autotests/findadv-15-in.txt
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ lyx-devel/trunk/development/autotests/findadv-15-in.txt     Fri May 27 
22:39:58 2011        (r38860)
@@ -0,0 +1,37 @@
+# Finding numbered maths with ignore-format on&off (might affect #7596)
+#
+Lang it_IT.utf8
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2 +x^2\C\[Home]
+KK: \Cs
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+# Uncheck ignore format
+KK: \Az\Ag\Ae
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 2\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 0\n with len: 1' lyx-log.txt
+
+TestBegin test.lyx -dbg find > lyx-log.txt 2>&1
+KK: \CF
+KK: \CM\Axmath-number-toggle\[Return]
+KK: x^2\[Return]\[Return]
+TestEnd
+Assert pcregrep -M 'Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 
0 pos: 2\n with len: 1' lyx-log.txt

Modified: lyx-devel/trunk/src/lyxfind.cpp
==============================================================================
--- lyx-devel/trunk/src/lyxfind.cpp     Fri May 27 22:37:29 2011        (r38859)
+++ lyx-devel/trunk/src/lyxfind.cpp     Fri May 27 22:39:58 2011        (r38860)
@@ -769,8 +769,9 @@
        while (regex_replace(t, t, 
"\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\{",
 "")
               || regex_replace(t, t, "^\\$", "")
               || regex_replace(t, t, "^\\\\\\[ ", "")
-              || regex_replace(t, t, "^\\\\item ", ""))
-               LYXERR(Debug::FIND, "  after removing leading $, \\[ , \\emph{, 
\\textbf{, etc.: " << t);
+              || regex_replace(t, t, "^\\\\item ", "")
+              || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\} ", ""))
+               LYXERR(Debug::FIND, "  after removing leading $, \\[ , \\emph{, 
\\textbf{, etc.: '" << t << "'");
        return s.find(t);
 }
 
@@ -789,14 +790,14 @@
                // Remove trailing closure of math, macros and environments, so 
to catch parts of them.
                do {
                        LYXERR(Debug::FIND, "par_as_string now is '" << 
par_as_string << "'");
-                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\]) ?\\$\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\])\\$\\'", "$1"))
                                        continue;
                        // @todo need to account for open square braces as well 
?
-                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\]) ?\\\\\\]\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\]) \\\\\\]\\'", "$1"))
                                        continue;
-                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\]) ?\\\\end\\{[a-zA-Z_]*\\}\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\]) \\\\end\\{[a-zA-Z_]*\\}\\'", "$1"))
                                        continue;
-                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\]) ?\\}\\'", "$1")) {
+                       if (regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\])\\}\\'", "$1")) {
                                ++open_braces;
                                continue;
                        }
@@ -820,10 +821,10 @@
                        // Insert .* before trailing '\$' ('$' has been escaped 
by escape_for_regex)
                        regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\])(\\\\\\$)\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\\\]' ('\]' has 
been escaped by escape_for_regex)
-                               || regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\])(\\\\\\\\\\\\\\])\\'", "$1(.*?)$2")
+                               || regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\])( \\\\\\\\\\\\\\])\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\\end\{...}' 
('\end{...}' has been escaped by escape_for_regex)
                                || regex_replace(par_as_string, par_as_string, 
-                                       
"(.*[^\\\\])(\\\\\\\\end\\\\\\{[a-zA-Z_]*\\\\\\})\\'", "$1(.*?)$2")
+                                       "(.*[^\\\\])( 
\\\\\\\\end\\\\\\{[a-zA-Z_]*\\\\\\})\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\}' ('}' has been 
escaped by escape_for_regex)
                                || regex_replace(par_as_string, par_as_string, 
"(.*[^\\\\])(\\\\\\})\\'", "$1(.*?)$2")
                ) {
@@ -1096,10 +1097,14 @@
                return 0;
        while (cur) {
                LYXERR(Debug::FIND, "findForwardAdv() cur: " << cur);
-               if (match(cur, -1, false)) {
+               int match_len = match(cur, -1, false);
+               LYXERR(Debug::FIND, "match_len: " << match_len);
+               if (match_len) {
                        for (; cur; cur.forwardPos()) {
                                LYXERR(Debug::FIND, "Advancing cur: " << cur);
-                               if (match(cur)) {
+                               int match_len = match(cur);
+                               LYXERR(Debug::FIND, "match_len: " << match_len);
+                               if (match_len) {
                                        // Sometimes in finalize we understand 
it wasn't a match
                                        // and we need to continue the outest 
loop
                                        int len = findAdvFinalize(cur, match);

Reply via email to