]> git.lyx.org Git - features.git/commitdiff
Overhaul (no)limits support
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 9 Dec 2020 08:39:49 +0000 (09:39 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 9 Dec 2020 13:10:17 +0000 (14:10 +0100)
- Add limits support to InsetMathScript
- Add limits support to InsetMathClass
- Fix bug where limits changing is disabled in inline math

Now the MathData objects remember whether they are in diaply mode.

Fixes bug #12045.

14 files changed:
src/mathed/InsetMath.h
src/mathed/InsetMathClass.cpp
src/mathed/InsetMathClass.h
src/mathed/InsetMathDecoration.cpp
src/mathed/InsetMathDecoration.h
src/mathed/InsetMathMacro.cpp
src/mathed/InsetMathMacro.h
src/mathed/InsetMathNest.cpp
src/mathed/InsetMathScript.cpp
src/mathed/InsetMathScript.h
src/mathed/InsetMathSymbol.cpp
src/mathed/InsetMathSymbol.h
src/mathed/MathData.cpp
src/mathed/MathData.h

index 220795695d8efdaca94ec5770055027e7c744b66..f5db673ac8e53b598f595c35f5580dec7c65a71d 100644 (file)
@@ -209,8 +209,8 @@ public:
 
        /// Whether the inset allows \(no)limits
        bool allowsLimitsChange() const { return mathClass() == MC_OP; }
-       /// The default limits value
-       virtual Limits defaultLimits() const { return NO_LIMITS; }
+       /// The default limits value depending on whether display mode is on
+       virtual Limits defaultLimits(bool /* display */) const { return NO_LIMITS; }
        /// whether the inset has limit-like sub/superscript
        virtual Limits limits() const { return AUTO_LIMITS; }
        /// sets types of sub/superscripts
index 2327cbe76d4e364276e2b2e2ee535bbaa6a66fef..f98aaa7ca5f8481dad5ac4bf0bf1b3b8c3bea339 100644 (file)
@@ -28,6 +28,15 @@ Inset * InsetMathClass::clone() const
 }
 
 
+Limits InsetMathClass::defaultLimits(bool display) const
+{
+       if (allowsLimitsChange() && display)
+               return LIMITS;
+       else
+               return NO_LIMITS;
+}
+
+
 void InsetMathClass::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
@@ -40,6 +49,13 @@ void InsetMathClass::draw(PainterInfo & pi, int x, int y) const
 }
 
 
+void InsetMathClass::write(WriteStream & os) const
+{
+       InsetMathNest::write(os);
+       writeLimits(os);
+}
+
+
 docstring InsetMathClass::name() const
 {
        return class_to_string(math_class_);
index 390d77aca04f39c1163eddae2041e13e50838902..60b79cedd65d994d95279e108022835d4da0c14d 100644 (file)
@@ -30,11 +30,19 @@ public:
        docstring name() const override;
        ///
        MathClass mathClass() const override { return math_class_; }
+       /// The default limits value in \c display style
+       Limits defaultLimits(bool display) const override;
+       /// whether the inset has limit-like sub/superscript
+       Limits limits() const override { return limits_; }
+       /// sets types of sub/superscripts
+       void limits(Limits lim) override { limits_ = lim; }
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const override;
        ///
        void draw(PainterInfo & pi, int x, int y) const override;
        ///
+       void write(WriteStream & os) const override;
+       ///
        void infoize(odocstream & os) const override;
        ///
        InsetCode lyxCode() const override { return MATH_CLASS_CODE; }
@@ -47,6 +55,8 @@ private:
        Inset * clone() const override;
        ///
        MathClass math_class_;
+       ///
+       Limits limits_ = AUTO_LIMITS;
 };
 
 
index 0349c69ee5f158a04997a38b5cb10cbccf272a3f..125aaa61e177c7c816ba8b4afe8d5d242c5a419a 100644 (file)
@@ -64,6 +64,15 @@ MathClass InsetMathDecoration::mathClass() const
 }
 
 
+Limits InsetMathDecoration::defaultLimits(bool display) const
+{
+       if (allowsLimitsChange() && display)
+               return LIMITS;
+       else
+               return NO_LIMITS;
+}
+
+
 bool InsetMathDecoration::protect() const
 {
        return
index 78f01a8207bc07fce67864d1adbfc1b760fb6766..ed329d8f20850701660fd8ed0c7ea39ce34b27cc 100644 (file)
@@ -39,8 +39,8 @@ public:
        void infoize(odocstream & os) const override;
        ///
        MathClass mathClass() const override;
-       /// The default limits value
-       Limits defaultLimits() const override { return allowsLimitsChange() ? LIMITS : NO_LIMITS; }
+       /// The default limits value in \c display style
+       Limits defaultLimits(bool display) const override;
        /// whether the inset has limit-like sub/superscript
        Limits limits() const override { return limits_; }
        /// sets types of sub/superscripts
index c35226fd6ca41af04334bf29dbff975fe0e9ae81..24409512e1ba7344d39031a195e8bdc6537aa32a 100644 (file)
@@ -398,14 +398,14 @@ bool InsetMathMacro::allowsLimitsChange() const
 }
 
 
-Limits InsetMathMacro::defaultLimits() const
+Limits InsetMathMacro::defaultLimits(bool display) const
 {
        if (d->expanded_.empty())
                return NO_LIMITS;
        // Guess from the expanded macro
        InsetMath const * in = d->expanded_.back().nucleus();
        Limits const lim = in->limits() == AUTO_LIMITS
-               ? in->defaultLimits() : in->limits();
+               ? in->defaultLimits(display) : in->limits();
        LATTEST(lim != AUTO_LIMITS);
        return lim;
 }
index 794819a0271e63d8b515e676eb658b092e55d8b7..ccc879b5139e80afe84ae38439f870d37ac9925e 100644 (file)
@@ -45,7 +45,7 @@ public:
        /// Whether the inset allows \(no)limits
        bool allowsLimitsChange() const;
        /// The default limits value
-       Limits defaultLimits() const override;
+       Limits defaultLimits(bool display) const override;
        /// whether the inset has limit-like sub/superscript
        Limits limits() const override;
        /// sets types of sub/superscripts
index 8974d2c985465e8100d9798ad457b5e2ba9bf4a4..44f4a26805663e2976f5b44fe0c9f878e3d37e74 100644 (file)
@@ -1299,10 +1299,12 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                                in->limits(NO_LIMITS);
                        else
                                in->limits(AUTO_LIMITS);
-               } else if (in->limits() == AUTO_LIMITS)
-                       in->limits(in->defaultLimits() == LIMITS ? NO_LIMITS : LIMITS);
-               else
+               } else if (in->limits() != AUTO_LIMITS)
                        in->limits(AUTO_LIMITS);
+               else if (in->defaultLimits(cur.cell().displayStyle()) == LIMITS)
+                       in->limits(NO_LIMITS);
+               else
+                       in->limits(LIMITS);
                return;
        }
 
index d88025b0b53f4415b6506ffdbd6c96b6a5f3d311..15ed90f131c7101114ef48493c617c42be16ffc1 100644 (file)
@@ -253,6 +253,23 @@ int InsetMathScript::nker(BufferView const * bv) const
 }
 
 
+Limits InsetMathScript::limits() const
+{
+       if (nuc().empty())
+               return AUTO_LIMITS;
+       else
+               // only the limits status of the last element counts
+               return nuc().back()->limits();
+}
+
+
+void InsetMathScript::limits(Limits lim)
+{
+       if (!nuc().empty())
+               nuc().back()->limits(lim);
+}
+
+
 MathClass InsetMathScript::mathClass() const
 {
        // FIXME: this is a hack, since the class will not be correct if
@@ -370,13 +387,12 @@ void InsetMathScript::drawT(TextPainter & pain, int x, int y) const
 
 bool InsetMathScript::hasLimits(FontInfo const & font) const
 {
-       if (font.style() != DISPLAY_STYLE)
-               return false;
        if (nuc().empty())
                return false;
 
        Limits const lim = nuc().back()->limits() == AUTO_LIMITS
-               ? nuc().back()->defaultLimits() : nuc().back()->limits();
+               ? nuc().back()->defaultLimits(font.style() == DISPLAY_STYLE)
+               : nuc().back()->limits();
        LASSERT(lim != AUTO_LIMITS, return false);
        return lim == LIMITS;
 }
index 37fc593372e6a5ca7f23a65e19486533689b3d50..1b34c5c7adf073f13446d4ff8f3b12bea7bc46d9 100644 (file)
@@ -32,6 +32,10 @@ public:
        InsetMathScript(Buffer * buf, MathAtom const & at, bool up);
        ///
        mode_type currentMode() const override { return MATH_MODE; }
+       /// whether the inset has limit-like sub/superscript
+       Limits limits() const override;
+       /// sets types of sub/superscripts
+       void limits(Limits lim) override;
        ///
        MathClass mathClass() const override;
        ///
index a87b0464edfbeaf7881d7de7fdf7cebf78394a7e..5c6d96fd4883377ee8d2650ea94af05ea119325e 100644 (file)
@@ -58,10 +58,12 @@ docstring InsetMathSymbol::name() const
 
 
 /// The default limits value
-Limits InsetMathSymbol::defaultLimits() const
+Limits InsetMathSymbol::defaultLimits(bool display) const
 {
-       return (allowsLimitsChange() && sym_->extra != "func")
-                       ? LIMITS : NO_LIMITS;
+       if (allowsLimitsChange() && sym_->extra != "func" && display)
+               return LIMITS;
+       else
+               return NO_LIMITS;
 }
 
 
index a04a237075d9019f5294c8d5c0a43a21b6e277c0..a21bc935eff1f0f371de29c7c1a4b794fe729f0a 100644 (file)
@@ -42,7 +42,7 @@ public:
        ///
        bool isOrdAlpha() const;
        /// The default limits value
-       Limits defaultLimits() const override;
+       Limits defaultLimits(bool display) const override;
        /// whether the inset has limit-like sub/superscript
        Limits limits() const override { return limits_; }
        /// sets types of sub/superscripts
index b4cbfe4ddd12c48fff24fdccea2a0b7e22e7cc68..c9db36c170b80a75ce50fc903baf0e5987e56eb6 100644 (file)
@@ -224,6 +224,7 @@ bool MathData::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
 {
        bool has_contents = false;
        BufferView * bv = mi.base.bv;
+       display_style_ = mi.base.font.style() == DISPLAY_STYLE;
        MathData * ar = const_cast<MathData*>(this);
        ar->updateMacros(&bv->cursor(), mi.macrocontext,
                         InternalUpdate, mi.base.macro_nesting);
index 0afaf182c364b6818fd4e3707fb790701c06c5db..ebc59d477a5e825c28118ca158f294b5d5a269f0 100644 (file)
@@ -146,6 +146,8 @@ public:
        MathClass mathClass() const;
        /// math class of last interesting element
        MathClass lastMathClass() const;
+       /// is the cell in display style
+       bool displayStyle() const { return display_style_; }
 
        /// access to cached x coordinate of last drawing
        int xo(BufferView const & bv) const;
@@ -192,6 +194,8 @@ protected:
        mutable int mindes_ = 0;
        mutable int slevel_ = 0;
        mutable int sshift_ = 0;
+       /// cached value for display style
+       mutable bool display_style_ = false;
        Buffer * buffer_ = nullptr;
 
 private: