]> git.lyx.org Git - features.git/commitdiff
Move updateMacros code into InsetMathMacroTemplate.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Thu, 12 Nov 2020 23:03:36 +0000 (18:03 -0500)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Fri, 13 Nov 2020 00:27:28 +0000 (19:27 -0500)
src/insets/InsetText.cpp
src/mathed/InsetMathMacroTemplate.cpp
src/mathed/InsetMathMacroTemplate.h

index dcf757621e816c70441d86d76c00dd7081e24526..6585586a7897abf7200d6c66500b2cc9b0b8299b 100644 (file)
@@ -963,21 +963,9 @@ void InsetText::updateMacros(DocIterator const & us, DocIterator const & scope)
                                continue;
 
                        // get macro data
-                       InsetMathMacroTemplate & macroTemplate =
-                               *insit.inset->asInsetMath()->asMacroTemplate();
-                       MacroContext mc(&buffer(), it);
-                       macroTemplate.updateToContext(mc);
-
-                       // valid?
-                       bool valid = macroTemplate.validMacro();
-                       // FIXME: Should be fixNameAndCheckIfValid() in fact,
-                       // then the BufferView's cursor will be invalid in
-                       // some cases which leads to crashes.
-                       if (!valid)
-                               continue;
-
-                       // register macro
-                       buffer().registerMacro(macroTemplate.name(), it, ourscope);
+                       InsetMathMacroTemplate * macroTemplate =
+                               insit.inset->asInsetMath()->asMacroTemplate();
+                       macroTemplate->updateMacros(it, ourscope);
                }
 
                // next paragraph
index e5c7db93556a03ce0e771ea7a42d369d932461ea..a445b4dd83bcfb51eb058c427f9257116ea86cd3 100644 (file)
@@ -460,6 +460,25 @@ docstring InsetMathMacroTemplate::name() const
 }
 
 
+void InsetMathMacroTemplate::updateMacros(DocIterator const & us, DocIterator const & scope)
+{
+       // This matches the previous code, but I am not sure why it
+       // should be like this.
+       DocIterator it = us;
+       it.pop_back();
+       MacroContext mc(&buffer(), it);
+       updateToContext(mc);
+       // FIXME: Should be fixNameAndCheckIfValid() in fact,
+       // then the BufferView's cursor will be invalid in
+       // some cases which leads to crashes.
+       if (!validMacro())
+               return;
+
+       // register macro
+       buffer().registerMacro(name(), it, scope);
+}
+
+
 void InsetMathMacroTemplate::updateToContext(MacroContext const & mc)
 {
        redefinition_ = mc.get(name()) != nullptr;
index 09408968d687caf33f837257171feae5bc8f87d0..7c9a680e29cf80d647965f5c658af9d6c2dd704b 100644 (file)
@@ -87,6 +87,8 @@ public:
 
        /// decide whether its a redefinition
        void updateToContext(MacroContext const & mc);
+       ///
+       void updateMacros(DocIterator const & us, DocIterator const & scope) override;
 
        ///
        void draw(PainterInfo & pi, int x, int y) const override;