[LyX/master] When a macro template is changed compute all new previews at once

Jean-Marc Lasgouttes lasgouttes at lyx.org
Fri Jun 26 17:47:31 UTC 2026


commit 4714aec6b4b02ccf01ac928371ed86ae5f4a39c6
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Fri Jun 26 10:39:14 2026 +0200

    When a macro template is changed compute all new previews at once
    
    When a math macro template is changed, it may be necessary to update
    the previews of math formulas after this point.
    
    However, the current code runs the preview machinery for each formula
    separately instead of accumulating snippets and computing all the
    previews at the same time.
    
    Thanks to Claude for the analysis.
    
    Fixes bug #13342.
---
 src/mathed/InsetMathHull.h            |  9 ++++-----
 src/mathed/InsetMathMacroTemplate.cpp | 11 ++++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h
index 247eb45d12..b6c748a5ca 100644
--- a/src/mathed/InsetMathHull.h
+++ b/src/mathed/InsetMathHull.h
@@ -166,6 +166,10 @@ public:
 	void notifyMouseSelectionDone(Cursor & cur) override;
 	///
 	bool insetAllowed(InsetCode code) const override;
+	/// Prepare the preview if preview is enabled.
+	/// \param forexport: whether this is intended for export
+	/// If so, we ignore LyXRC and wait for the image to be generated.
+	void preparePreview(DocIterator const & pos, bool forexport = false) const;
 	///
 	void addPreview(DocIterator const & inset_pos,
 		graphics::PreviewLoader &) const override;
@@ -212,11 +216,6 @@ protected:
 
 private:
 	Inset * clone() const override;
-	/// Prepare the preview if preview is enabled.
-	/// \param forexport: whether this is intended for export
-	/// If so, we ignore LyXRC and wait for the image to be generated.
-	void preparePreview(DocIterator const & pos,
-	                    bool forexport = false) const;
 	/// like reloadPreview, but forces load
 	/// used by image export
 	void loadPreview(DocIterator const & pos) const;
diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp
index 23b143842d..1d73fd2cf4 100644
--- a/src/mathed/InsetMathMacroTemplate.cpp
+++ b/src/mathed/InsetMathMacroTemplate.cpp
@@ -36,6 +36,8 @@
 
 #include "frontends/Painter.h"
 
+#include "graphics/PreviewLoader.h"
+
 #include "insets/RenderPreview.h"
 
 #include "support/lassert.h"
@@ -855,14 +857,13 @@ void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
 
 	if (!preview_hulls.empty()) {
 		// reload the scheduled previews
-		set<DocIterator>::const_iterator sit = preview_hulls.begin();
-		set<DocIterator>::const_iterator end = preview_hulls.end();
-		for (; sit != end; ++sit) {
+		for (auto const & sit : preview_hulls) {
 			InsetMathHull * inset_hull =
-				sit->nextInset()->asInsetMath()->asHullInset();
+				sit.nextInset()->asInsetMath()->asHullInset();
 			LBUFERR(inset_hull);
-			inset_hull->reloadPreview(*sit);
+			inset_hull->preparePreview(sit);
 		}
+		inset_pos.buffer()->loader()->startLoading();
 		cur.screenUpdateFlags(Update::Force);
 	}
 }


More information about the lyx-cvs mailing list