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
This commit is contained in:
Tommaso Cucinotta 2011-05-27 20:39:58 +00:00
parent 3f8ae08390
commit 386c8291ed
3 changed files with 89 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -769,8 +769,9 @@ static size_t identifyLeading(string const & s) {
while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\{", "") 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, "^\\\\\\[ ", "") || regex_replace(t, t, "^\\\\\\[ ", "")
|| regex_replace(t, t, "^\\\\item ", "")) || regex_replace(t, t, "^\\\\item ", "")
LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: " << t); || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\} ", ""))
LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'");
return s.find(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. // Remove trailing closure of math, macros and environments, so to catch parts of them.
do { do {
LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'"); 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; continue;
// @todo need to account for open square braces as well ? // @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; 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; continue;
if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\}\\'", "$1")) { if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\])\\}\\'", "$1")) {
++open_braces; ++open_braces;
continue; continue;
} }
@ -820,10 +821,10 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
// Insert .* before trailing '\$' ('$' has been escaped by escape_for_regex) // 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 '\\\]' ('\]' has been escaped by escape_for_regex) // 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) // Insert .* before trailing '\\end\{...}' ('\end{...}' has been escaped by escape_for_regex)
|| regex_replace(par_as_string, par_as_string, || 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) // 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")
) { ) {
@ -1096,10 +1097,14 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
return 0; return 0;
while (cur) { while (cur) {
LYXERR(Debug::FIND, "findForwardAdv() cur: " << 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()) { for (; cur; cur.forwardPos()) {
LYXERR(Debug::FIND, "Advancing cur: " << cur); 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 // Sometimes in finalize we understand it wasn't a match
// and we need to continue the outest loop // and we need to continue the outest loop
int len = findAdvFinalize(cur, match); int len = findAdvFinalize(cur, match);