From 386c8291ed5c33b1ace9795fc11b2ca2bad6623c Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Fri, 27 May 2011 20:39:58 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38860 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/autotests/findadv-14-in.txt | 37 +++++++++++++++++++++++++ development/autotests/findadv-15-in.txt | 37 +++++++++++++++++++++++++ src/lyxfind.cpp | 25 ++++++++++------- 3 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 development/autotests/findadv-14-in.txt create mode 100644 development/autotests/findadv-15-in.txt diff --git a/development/autotests/findadv-14-in.txt b/development/autotests/findadv-14-in.txt new file mode 100644 index 0000000000..a5ae4c426d --- /dev/null +++ b/development/autotests/findadv-14-in.txt @@ -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 diff --git a/development/autotests/findadv-15-in.txt b/development/autotests/findadv-15-in.txt new file mode 100644 index 0000000000..c615e6016a --- /dev/null +++ b/development/autotests/findadv-15-in.txt @@ -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 diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 1aa228b4a5..ac3db2d6e3 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -769,8 +769,9 @@ static size_t identifyLeading(string const & s) { 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 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & // 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 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & // 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 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) 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); -- 2.39.5