]> git.lyx.org Git - features.git/commitdiff
Fix crash with quick search starting with mathed selection
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 30 Mar 2024 09:14:34 +0000 (10:14 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 30 Mar 2024 09:14:34 +0000 (10:14 +0100)
setCursorSelection does not work with math. Copy the method from
spellchecker.

src/lyxfind.cpp

index edf21d402252fbf80cfe96a4de8732a32f118cfe..6281b82abc8c143c2ebb7dd4bd5a561c8761028b 100644 (file)
@@ -281,6 +281,27 @@ bool searchAllowed(docstring const & str)
        return true;
 }
 
+void setSelection(BufferView * bv, DocIterator const & from, DocIterator const & to)
+{
+       DocIterator end = to;
+
+       if (from.pit() != end.pit()) {
+               // there are multiple paragraphs in selection
+               Cursor & bvcur = bv->cursor();
+               bvcur.setCursor(from);
+               bvcur.clearSelection();
+               bvcur.selection(true);
+               bvcur.setCursor(end);
+               bvcur.selection(true);
+       } else {
+               // FIXME LFUN
+               // If we used a LFUN, dispatch would do all of this for us
+               int const size = end.pos() - from.pos();
+               bv->putSelectionAt(from, size, false);
+       }
+       bv->processUpdateFlags(Update::Force | Update::FitCursor);
+}
+
 } // namespace
 
 
@@ -387,7 +408,7 @@ bool findOne(BufferView * bv, docstring const & searchstr,
                // restore original selection
                if (had_selection) {
                        bv->cursor().resetAnchor();
-                       bv->setCursorSelectionTo(endcur);
+                       setSelection(bv, startcur, endcur);
                }
                return false;
        }
@@ -464,7 +485,7 @@ int replaceAll(BufferView * bv,
        if (had_selection) {
                endcur.fixIfBroken();
                bv->cursor().resetAnchor();
-               bv->setCursorSelectionTo(endcur);
+               setSelection(bv, startcur, endcur);
        }
 
        return num;