Author: tommaso
Date: Thu Jan 27 00:06:02 2011
New Revision: 37333
URL: http://www.lyx.org/trac/changeset/37333

Log:
Puts the selection at the correct position after replacing math contents with 
Advanced Search.
Fixes crashes reported as #7245 and also #7241.

Modified:
   lyx-devel/trunk/src/lyxfind.cpp

Modified: lyx-devel/trunk/src/lyxfind.cpp
==============================================================================
--- lyx-devel/trunk/src/lyxfind.cpp     Wed Jan 26 19:35:25 2011        (r37332)
+++ lyx-devel/trunk/src/lyxfind.cpp     Thu Jan 27 00:06:02 2011        (r37333)
@@ -1107,6 +1107,7 @@
 docstring stringifyFromForSearch(FindAndReplaceOptions const & opt,
        DocIterator const & cur, int len)
 {
+       LASSERT(cur.pos() >= 0 && cur.pos() <= cur.lastpos(), /* */);
        if (!opt.ignoreformat)
                return latexifyFromCursor(cur, len);
        else
@@ -1215,6 +1216,7 @@
                                        repl_buffer.params().documentClassPtr(),
                                        bv->buffer().errorList("Paste"));
                LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << 
endl);
+               cur.pos() -= repl_buffer.paragraphs().begin()->size();
        } else {
                odocstringstream ods;
                OutputParams runparams(&repl_buffer.params().encoding());
@@ -1234,7 +1236,6 @@
                LYXERR(Debug::FIND, "Replacing by niceInsert()ing latex: '" << 
repl_latex << "'");
                cur.niceInsert(repl_latex);
        }
-       cur.pos() -= repl_buffer.paragraphs().begin()->size();
        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);
        bv->processUpdateFlags(Update::Force);

Reply via email to