From e05d115be8de363c954730bb4665cf2196ec633a Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Wed, 26 Jan 2011 23:54:12 +0000 Subject: [PATCH] Fixing regression bug after last commit. Couldn't find anything better, however now it apparently works and doesn't crash (when replacing text which is longer than the replaced contents in math mode and similar). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37335 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/lyxfind.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index a594703d91..752aaaec5b 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -1216,7 +1216,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M repl_buffer.params().documentClassPtr(), bv->buffer().errorList("Paste")); LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl); - cur.pos() -= repl_buffer.paragraphs().begin()->size(); + sel_len = repl_buffer.paragraphs().begin()->size(); } else { odocstringstream ods; OutputParams runparams(&repl_buffer.params().encoding()); @@ -1234,10 +1234,13 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M regex_replace(s, s, "\\\\\\[(.*)\\\\\\]", "$1"); repl_latex = from_utf8(s); LYXERR(Debug::FIND, "Replacing by niceInsert()ing latex: '" << repl_latex << "'"); - cur.niceInsert(repl_latex); + sel_len = cur.niceInsert(repl_latex); } - LYXERR(Debug::FIND, "Putting selection at cur=" << cur << " with len: " << repl_buffer.paragraphs().begin()->size()); - bv->putSelectionAt(DocIterator(cur), repl_buffer.paragraphs().begin()->size(), !opt.forward); + cur.pos() -= sel_len; + if (cur.pos() < 0) + cur.pos() = 0; + LYXERR(Debug::FIND, "Putting selection at cur=" << cur << " with len: " << sel_len); + bv->putSelectionAt(DocIterator(cur), sel_len, !opt.forward); bv->processUpdateFlags(Update::Force); } -- 2.39.2