From babb5b007bdb273c12255edf7c84a537327c0400 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 30 Mar 2024 10:14:34 +0100 Subject: [PATCH] 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; -- 2.39.5