[LyX features/biginset] Fix crash with quick search starting with mathed selection

Juergen Spitzmueller spitz at lyx.org
Fri Apr 5 13:41:46 UTC 2024


commit babb5b007bdb273c12255edf7c84a537327c0400
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sat Mar 30 10:14:34 2024 +0100

    Fix crash with quick search starting with mathed selection
    
    setCursorSelection does not work with math. Copy the method from
    spellchecker.
---
 src/lyxfind.cpp | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index edf21d4022..6281b82abc 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -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;


More information about the lyx-cvs mailing list