[LyX/master] Force metrics calculation when entering a previewed inset

Jean-Marc Lasgouttes lasgouttes at lyx.org
Sat Sep 20 09:45:55 UTC 2025


commit fe0ef5c02abde14d2a7d309c1e0f4d455884d4eb
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Sun Sep 14 20:48:43 2025 +0200

    Force metrics calculation when entering a previewed inset
    
    The safe part:
    
    - change notifyCursorEnters to use two parameters (it was not yet used)
    
    - in previewed insets, force a metrics computation when entering the inset
    
    The less obvious part:
    
    - in BufferView::dispatch(), copy the cursor screenUpdate() flags to
      the DispatchResult parameter of the method after calling
      notifyCursorLeavesOrEnters().
    
    - In BufferView::processUpdateFlags() do the SinglePar update thing
      even when ForceDraw is required. I *think* this made sense when
      ForceDraw was added after computing metrics with Force, but that
      this is not needed anymore because we use if/else.
    
    Fixes bug #13225.
---
 src/BufferView.cpp           |  3 ++-
 src/Cursor.cpp               |  2 +-
 src/insets/Inset.h           |  2 +-
 src/insets/InsetIPA.cpp      |  7 +++++++
 src/insets/InsetIPA.h        |  2 ++
 src/insets/InsetPreview.cpp  |  7 +++++++
 src/insets/InsetPreview.h    |  2 ++
 src/mathed/InsetMathHull.cpp | 17 +++++++++++++++++
 src/mathed/InsetMathHull.h   |  2 ++
 9 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index c498d29248..8e7186db03 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -581,7 +581,7 @@ void BufferView::processUpdateFlags(Update::flags flags)
 	 * We handle this before FitCursor because the later will require
 	 * correct metrics at cursor position.
 	 */
-	else if ((flags & Update::SinglePar) && !(flags & Update::ForceDraw)) {
+	else if (flags & Update::SinglePar) {
 		if (singleParUpdate())
 			updateMetrics(false);
 		else
@@ -2686,6 +2686,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 			cursor().fixIfBroken();
 			resetInlineCompletionPos();
 		}
+		dr.screenUpdate(dr.screenUpdate() | cursor().result().screenUpdate());
 		old.endUndoGroup();
 	}
 }
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 9eff395746..656ee90dce 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -2475,7 +2475,7 @@ bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur)
 	// notify everything on top of the common part in new cursor,
 	// but stop if the inset claims the cursor to be invalid now
 	for (; i < cur.depth(); ++i) {
-		if (cur[i].inset().notifyCursorEnters(cur))
+		if (cur[i].inset().notifyCursorEnters(old, cur))
 			return true;
 	}
 
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 5a47be6a7a..653fffa729 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -325,7 +325,7 @@ public:
 	/// anymore.
 	/// \c cur is the new cursor, some slice points to this. Use the update
 	/// flags to cause a redraw.
-	virtual bool notifyCursorEnters(Cursor & /*cur*/)
+	virtual bool notifyCursorEnters(Cursor const & /*old*/, Cursor & /*cur*/)
 		{ return false; }
 	/// is called when the mouse enters or leaves this inset
 	/// return true if this inset needs a repaint
diff --git a/src/insets/InsetIPA.cpp b/src/insets/InsetIPA.cpp
index e13b3ef6e7..6e38bf7614 100644
--- a/src/insets/InsetIPA.cpp
+++ b/src/insets/InsetIPA.cpp
@@ -208,6 +208,13 @@ void InsetIPA::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
+bool InsetIPA::notifyCursorEnters(Cursor const & old, Cursor & cur)
+{
+	cur.screenUpdateFlags(Update::Force);
+	return InsetText::notifyCursorLeaves(old, cur);
+}
+
+
 bool InsetIPA::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
 	reloadPreview(old);
diff --git a/src/insets/InsetIPA.h b/src/insets/InsetIPA.h
index a1b73b4d57..c7a5fd44e4 100644
--- a/src/insets/InsetIPA.h
+++ b/src/insets/InsetIPA.h
@@ -66,6 +66,8 @@ public:
 	void addPreview(DocIterator const & inset_pos,
 		graphics::PreviewLoader & ploader) const override;
 
+	bool notifyCursorEnters(Cursor const & old, Cursor & cur) override;
+
 	bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
 
 	void write(std::ostream & os) const override;
diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp
index dabbf5ece2..9f3f7d1a15 100644
--- a/src/insets/InsetPreview.cpp
+++ b/src/insets/InsetPreview.cpp
@@ -215,6 +215,13 @@ Inset * InsetPreview::editXY(Cursor & cur, int x, int y)
 }
 
 
+bool InsetPreview::notifyCursorEnters(Cursor const & old, Cursor & cur)
+{
+	cur.screenUpdateFlags(Update::Force);
+	return InsetText::notifyCursorEnters(old, cur);
+}
+
+
 bool InsetPreview::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
 	reloadPreview(old);
diff --git a/src/insets/InsetPreview.h b/src/insets/InsetPreview.h
index 32f2335dc3..6bd30f2217 100644
--- a/src/insets/InsetPreview.h
+++ b/src/insets/InsetPreview.h
@@ -67,6 +67,8 @@ public:
 
 	Inset * editXY(Cursor & cur, int x, int y) override;
 
+	bool notifyCursorEnters(Cursor const & old, Cursor & cur) override;
+
 	bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
 
 	void write(std::ostream & os) const override;
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 70b0df7165..230de78a6f 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -943,6 +943,23 @@ bool InsetMathHull::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 }
 
 
+bool InsetMathHull::notifyCursorEnters(Cursor const & old, Cursor & cur)
+{
+	if (RenderPreview::previewMath()) {
+		/** FIXME: currently, SinglePar operates on the current
+		 * paragraph at processUpdateFlags time (here cur) and not the
+		 * paragraph where the change happened (old). When this is
+		 * fixed, the following test will become useless.
+		 */
+		if (&old.innerParagraph() == &cur.innerParagraph())
+			cur.screenUpdateFlags(Update::SinglePar);
+		else
+			cur.screenUpdateFlags(Update::Force);
+	}
+	return false;
+}
+
+
 bool InsetMathHull::insetAllowed(InsetCode code) const
 {
 	switch (code) {
diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h
index 905d5d9d40..1a4eeec8d4 100644
--- a/src/mathed/InsetMathHull.h
+++ b/src/mathed/InsetMathHull.h
@@ -157,6 +157,8 @@ public:
 	///
 	void forOutliner(docstring &, size_t const, bool const) const override;
 
+	/// get notification when the cursor enters this inset
+	bool notifyCursorEnters(Cursor const & old, Cursor & cur) override;
 	/// get notification when the cursor leaves this inset
 	bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
 	///


More information about the lyx-cvs mailing list