commit 1bc6a0f3014b3a9a9da0f5ec136716ff27479c14
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Thu Jan 8 19:36:08 2026 +0100

    Check whether cache is OK before calling coordOffset().
    
    Introduce new method BufferView::hasCacheFor() that makes sure that
    coordOffset will not assert.
    
    Use it in scrollToCursor instead of TextMetrics::contains(pit). This
    makes sense when a search command has auto-opened a collapsible inset.
---
 src/BufferView.cpp | 21 ++++++++++++++++++++-
 src/BufferView.h   |  2 ++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 9c74583c03..6731a63078 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1119,7 +1119,7 @@ bool BufferView::scrollToCursor(DocIterator const & dit, 
ScrollType how)
        pit_type const old_pit = d->anchor_pit_;
        int const old_ypos = d->anchor_ypos_;
 
-       if (!tm.contains(bot_pit))
+       if (!hasCacheFor(dit))
                tm.redoParagraph(bot_pit);
        int const offset = coordOffset(dit).y;
 
@@ -3522,6 +3522,25 @@ void BufferView::insertLyXFile(FileName const & fname, 
bool const ignorelang)
 }
 
 
+bool BufferView::hasCacheFor(DocIterator const & dit) const
+{
+       for (size_t i = 0 ; i < dit.depth() ; ++i) {
+               CursorSlice const & sl = dit[i];
+               if (!coordCache().insets().hasDim(&sl.inset()))
+                       return false;
+               if (sl.inset().inMathed()) {
+                       if (!coordCache().cells().hasDim(&sl.cell()))
+                               return false;
+               } else {
+                       TextMetrics const & tm = textMetrics(sl.text());
+                       if (!tm.contains(sl.pit()))
+                               return false;
+               }
+       }
+       return true;
+}
+
+
 Point BufferView::coordOffset(DocIterator const & dit) const
 {
        int x = 0;
diff --git a/src/BufferView.h b/src/BufferView.h
index 000869edee..eca7f84ccc 100644
--- a/src/BufferView.h
+++ b/src/BufferView.h
@@ -420,6 +420,8 @@ private:
        BufferView(BufferView const &);
        void operator=(BufferView const &);
 
+       /// Returns true if there is enough cache information for coordOffset.
+       bool hasCacheFor(DocIterator const & dit) const;
        /// the position relative to (0, baseline) of outermost paragraph
        Point coordOffset(DocIterator const & dit) const;
        /// Update current paragraph metrics.
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to