[LyX/2.5.x] Check whether cache is OK before calling coordOffset().

Jean-Marc Lasgouttes <[email protected]>
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 68e1eb3494736b97e4b6dcbedbad32277aaebb27
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) which
    was temporarily removed at 4cbe42d0. This makes sense when a search
    command has auto-opened a collapsible inset.
    
    (cherry picked from commit 1bc6a0f3014b3a9a9da0f5ec136716ff27479c14)
---
 src/BufferView.cpp | 22 +++++++++++++++++++++-
 src/BufferView.h   |  2 ++
 status.25x         |  1 +
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index e73f7563f4..7dc58b000d 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1118,7 +1118,8 @@ bool BufferView::scrollToCursor(DocIterator const & dit, ScrollType how)
 	pit_type const old_pit = d->anchor_pit_;
 	int const old_ypos = d->anchor_ypos_;
 
-	tm.redoParagraph(bot_pit);
+	if (!hasCacheFor(dit))
+		tm.redoParagraph(bot_pit);
 	int const offset = coordOffset(dit).y;
 
 	CursorSlice const & cs = dit.innerTextSlice();
@@ -3492,6 +3493,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.
diff --git a/status.25x b/status.25x
index b7d386df85..2e99134204 100644
--- a/status.25x
+++ b/status.25x
@@ -78,6 +78,7 @@ What's new
 - Fix PDF->PNG conversion problem on macOS. Now gs takes priority over sips
   on that os (bug 12632).
 
+- Reintroduce a proper version of a broken optimization that was removed for 2.5.0.
 
 * INTERNALS
 
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.