]> git.lyx.org Git - features.git/commitdiff
Applying (variation of) fix by stwitt to solve #7172.
authorTommaso Cucinotta <tommaso@lyx.org>
Wed, 29 Dec 2010 19:59:41 +0000 (19:59 +0000)
committerTommaso Cucinotta <tommaso@lyx.org>
Wed, 29 Dec 2010 19:59:41 +0000 (19:59 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37043 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/FindAndReplace.cpp
src/lyxfind.cpp

index 7b372c04c9d923efed1dc5356d848814f7633a78..13537613ac121159ff2a3ec5011ea5c00aa0cce8 100644 (file)
@@ -330,11 +330,11 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt)
                dispatch(cmd);
                LYXERR(Debug::FIND, "dispatched");
                if (bv->cursor().result().dispatched()) {
-                       // Match found, selected and replaced if needed
+                       // New match found and selected (old selection replaced if needed)
                        return;
                }
 
-               // No match found in current buffer:
+               // No match found in current buffer (however old selection might have been replaced)
                // select next buffer in scope, if any
                bool prompt = nextPrevBuffer(buf, opt);
                if (prompt) {
@@ -367,6 +367,9 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt)
                lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
                                          buf_orig->absFileName()));
        bv = view_.documentBufferView();
+       // This may happen after a replace occurred
+       if (cur_orig.pos() > cur_orig.lastpos())
+               cur_orig.pos() = cur_orig.lastpos();
        bv->cursor().setCursor(cur_orig);
 }
 
index d65ca1571aab7b124ddf004822be21efd92a5b39..d292364d979f130d436f6cb7eb37afefb7a667c2 100644 (file)
@@ -1203,9 +1203,11 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
        cap::cutSelection(cur, false, false);
        if (!cur.inMathed()) {
                LYXERR(Debug::FIND, "Replacing by pasteParagraphList()ing repl_buffer");
+               LYXERR(Debug::FIND, "Before pasteParagraphList() cur=" << cur << endl);
                cap::pasteParagraphList(cur, repl_buffer.paragraphs(),
                                        repl_buffer.params().documentClassPtr(),
                                        bv->buffer().errorList("Paste"));
+               LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
        } else {
                odocstringstream ods;
                OutputParams runparams(&repl_buffer.params().encoding());
@@ -1226,6 +1228,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                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);
 }
@@ -1235,7 +1238,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
 bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt)
 {
        DocIterator cur;
-       int match_len;
+       int match_len = 0;
 
        if (opt.search.empty()) {
                bv->message(_("Search text is empty!"));