From 604b07c4d12167d0c52a3b68baadc2729e10d5a3 Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Tue, 12 Jul 2011 15:58:53 +0000 Subject: [PATCH] After replacing with multi-cell contents inside maths, now advanced find and replace leaves the cursor after the inserted material. Addressing #7675. Added accompanying regression test. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39282 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/autotests/findadv-20-in.txt | 26 +++++++++++++++++++++++++ src/lyxfind.cpp | 10 +++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 development/autotests/findadv-20-in.txt diff --git a/development/autotests/findadv-20-in.txt b/development/autotests/findadv-20-in.txt new file mode 100644 index 0000000000..05b62b475c --- /dev/null +++ b/development/autotests/findadv-20-in.txt @@ -0,0 +1,26 @@ +# Avoiding recursive replacements when replaced text matches search pattern +# Addresses #7675. +# +Lang it_IT.utf8 + +TestBegin test.lyx -dbg find > lyx-log.txt 2>&1 +KK: a a a\C\[Home] +KK: \CF +KK: a\[Tab] +KK: \Cm\\frac 1\[Down]a\[Return]\[Return]\[Return] +KK: \Cs +KK: \Ax +KK: buffer-export latex\[Return] +TestEnd +Assert pcregrep -M '^\$\\frac\{1\}\{a\}\$ \$\\frac\{1\}\{a\}\$ a' test.tex + +TestBegin test2.lyx -dbg find > lyx-log.txt 2>&1 +KK: \Cma \Cma \Cma \C\[Home] +KK: \CF +KK: a\[Tab] +KK: \Cm\\frac 1\[Down]a\[Return]\[Return]\[Return] +KK: \Cs +KK: \Ax +KK: buffer-export latex\[Return] +TestEnd +Assert pcregrep -M '^\$\\frac\{1\}\{a\}\$ \$\\frac\{1\}\{a\}\$ \$a\$' test2.tex diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 486d10fe9e..16527c0290 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -1377,14 +1377,18 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M regex_replace(to_utf8(repl_latex), s, "\\$(.*)\\$", "$1"); regex_replace(s, s, "\\\\\\[(.*)\\\\\\]", "$1"); repl_latex = from_utf8(s); - LYXERR(Debug::FIND, "Replacing by niceInsert()ing latex: '" << repl_latex << "'"); - sel_len = cur.niceInsert(repl_latex); + LYXERR(Debug::FIND, "Replacing by insert()ing latex: '" << repl_latex << "' cur=" << cur << " with depth=" << cur.depth()); + MathData ar(cur.buffer()); + asArray(repl_latex, ar, Parse::NORMAL); + cur.insert(ar); + sel_len = ar.size(); + LYXERR(Debug::FIND, "After insert() cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len); } if (cur.pos() >= sel_len) cur.pos() -= sel_len; else cur.pos() = 0; - LYXERR(Debug::FIND, "Putting selection at cur=" << cur << " with len: " << sel_len); + LYXERR(Debug::FIND, "After pos adj cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len); bv->putSelectionAt(DocIterator(cur), sel_len, !opt.forward); bv->processUpdateFlags(Update::Force); bv->buffer().updatePreviews(); -- 2.39.5