]> git.lyx.org Git - lyx.git/commitdiff
Factor out the code that handles default macro arguments
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 28 Nov 2016 12:13:36 +0000 (13:13 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 2 Dec 2016 13:56:09 +0000 (14:56 +0100)
src/mathed/MathMacro.cpp

index a2a597f985dba2e90112ad41ee312a87ff41f5d6..0a47aa2e9fd4731b43225e0fa82b99471155ec8c 100644 (file)
@@ -68,6 +68,14 @@ public:
        MathMacro const * owner() { return mathMacro_; }
        ///
        InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
+       /// The math data to use for display
+       MathData const & displayCell(BufferView const * bv) const
+       {
+               // handle default macro arguments
+               bool use_def_arg = !mathMacro_->editMetrics(bv)
+                       && mathMacro_->cell(idx_).empty();
+               return use_def_arg ? def_ : mathMacro_->cell(idx_);
+       }
        ///
        bool addToMathRow(MathRow & mrow, MetricsInfo & mi) const
        {
@@ -82,13 +90,7 @@ public:
                mrow.push_back(e_beg);
 
                mathMacro_->macro()->unlock();
-               bool has_contents;
-               // handle default macro arguments
-               if (!mathMacro_->editMetrics(mi.base.bv)
-                       && mathMacro_->cell(idx_).empty())
-                       has_contents = def_.addToMathRow(mrow, mi);
-               else
-                       has_contents = mathMacro_->cell(idx_).addToMathRow(mrow, mi);
+               bool has_contents = displayCell(mi.base.bv).addToMathRow(mrow, mi);
                mathMacro_->macro()->lock();
 
                // if there was no contents, and the contents is editable,
@@ -137,11 +139,7 @@ public:
        ///
        int kerning(BufferView const * bv) const
        {
-               if (mathMacro_->editMetrics(bv)
-                   || !mathMacro_->cell(idx_).empty())
-                       return mathMacro_->cell(idx_).kerning(bv);
-               else
-                       return def_.kerning(bv);
+               return displayCell(bv).kerning(bv);
        }
 
 private: