From: Richard Kimberly Heck Date: Thu, 12 Nov 2020 23:03:36 +0000 (-0500) Subject: Move updateMacros code into InsetMathMacroTemplate. X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e19bf434f61c100cef88f7515026e0a36e4b39df;p=features.git Move updateMacros code into InsetMathMacroTemplate. --- diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index dcf757621e..6585586a78 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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 diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp index e5c7db9355..a445b4dd83 100644 --- a/src/mathed/InsetMathMacroTemplate.cpp +++ b/src/mathed/InsetMathMacroTemplate.cpp @@ -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; diff --git a/src/mathed/InsetMathMacroTemplate.h b/src/mathed/InsetMathMacroTemplate.h index 09408968d6..7c9a680e29 100644 --- a/src/mathed/InsetMathMacroTemplate.h +++ b/src/mathed/InsetMathMacroTemplate.h @@ -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;