]> git.lyx.org Git - lyx.git/commitdiff
Allow toggling (no)limits only after mathop symbol
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 3 Sep 2018 15:49:54 +0000 (17:49 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 5 Jan 2019 14:18:09 +0000 (15:18 +0100)
In particular, introduce the new InsetMathScript::allowLimits method
that checks for that and honor it in getStatus/ddoDispatch.

Do the same for (over|under)brace

(cherry picked from commit 7b7ed64a0e760eccad5fff7fa944b983d0bed025)
(cherry picked from commit 6cfd733dea70bf26c512dea8491f79f68cb512e6)

src/mathed/InsetMathDecoration.cpp
src/mathed/InsetMathDecoration.h
src/mathed/InsetMathScript.cpp
src/mathed/InsetMathScript.h
status.23x

index 908a887eebb5bbea01d8a944d3885293b42a2acc..1262370953fe4a89c9808cc94dc2c7a3a27a59b0 100644 (file)
@@ -55,11 +55,17 @@ bool InsetMathDecoration::upper() const
 }
 
 
+MathClass InsetMathDecoration::mathClass() const
+{
+       if (key_->name == "overbrace" || key_->name == "underbrace")
+               return MC_OP;
+       return MC_ORD;
+}
+
+
 bool InsetMathDecoration::isScriptable() const
 {
-       return
-                       key_->name == "overbrace" ||
-                       key_->name == "underbrace";
+       return mathClass() == MC_OP;
 }
 
 
index 9e58065ee3f8c76bcc9106edf2c495c317f97088..a5d5e9c9b8d53677a3fa8a87ca9665a8143cf378 100644 (file)
@@ -38,6 +38,8 @@ public:
        ///
        void infoize(odocstream & os) const;
        ///
+       MathClass mathClass() const;
+       ///
        bool isScriptable() const;
        ///
        void validate(LaTeXFeatures & features) const;
index 57f3b87f88299414f9b4649f75d7c0d46107153f..315637c2dadcf1edfebf1e3f3a55abdf276b48ac 100644 (file)
@@ -381,6 +381,20 @@ void InsetMathScript::drawT(TextPainter & pain, int x, int y) const
 }
 
 
+// FIXME: See InsetMathSymbol::takesLimits, which seems to attempt the
+// same in a hardcoded way. takeLimits use is currently commented out in
+// InsetMathScript::metrics. It seems that the mathop test is general
+// enough, but only time will tell.
+bool InsetMathScript::allowsLimits() const
+{
+       if (nuc().empty())
+               return false;
+       // Only makes sense for insets of mathop class
+       if (nuc().back()->mathClass() != MC_OP)
+               return false;
+       return true;
+}
+
 
 bool InsetMathScript::hasLimits() const
 {
@@ -391,8 +405,9 @@ bool InsetMathScript::hasLimits() const
                return false;
 
        // we can only display limits if the nucleus wants some
-       if (nuc().empty())
+       if (!allowsLimits())
                return false;
+       // FIXME: this is some hardcoding done in InsetMathSymbol::metrics.
        if (!nuc().back()->isScriptable())
                return false;
 
@@ -751,6 +766,9 @@ void InsetMathScript::doDispatch(Cursor & cur, FuncRequest & cmd)
        //LYXERR("InsetMathScript: request: " << cmd);
 
        if (cmd.action() == LFUN_MATH_LIMITS) {
+               // only when nucleus allows this
+               if (!allowsLimits())
+                       return;
                cur.recordUndoInset();
                if (!cmd.argument().empty()) {
                        if (cmd.argument() == "limits")
@@ -774,15 +792,19 @@ bool InsetMathScript::getStatus(Cursor & cur, FuncRequest const & cmd,
                                FuncStatus & flag) const
 {
        if (cmd.action() == LFUN_MATH_LIMITS) {
-               if (!cmd.argument().empty()) {
-                       if (cmd.argument() == "limits")
-                               flag.setOnOff(limits_ == 1);
-                       else if (cmd.argument() == "nolimits")
-                               flag.setOnOff(limits_ == -1);
-                       else
-                               flag.setOnOff(limits_ == 0);
-               }
-               flag.setEnabled(true);
+               // only when nucleus allows this
+               if (allowsLimits()) {
+                       if (!cmd.argument().empty()) {
+                               if (cmd.argument() == "limits")
+                                       flag.setOnOff(limits_ == 1);
+                               else if (cmd.argument() == "nolimits")
+                                       flag.setOnOff(limits_ == -1);
+                               else
+                                       flag.setOnOff(limits_ == 0);
+                       }
+                       flag.setEnabled(true);
+               } else
+                       flag.setEnabled(false);
                return true;
        }
 
index 0b96d03ce2e03bdc9307229d93136b35c5c0c934..51c8a2f710799d330271cc8734509889cfa0cbff 100644 (file)
@@ -140,6 +140,8 @@ private:
        /// shifts the superscript to the right, and a negative value shifts the
        /// subscript to the left.
        int nker(BufferView const * bv) const;
+       /// can one change how scripts are drawn?
+       bool allowsLimits() const;
        /// where do we have to draw the scripts?
        bool hasLimits() const;
        /// clean up empty cells and return true if a cell has been deleted.
index 07e2adcb0436ce31261d3a5c65ab841cde3948f4..c35e9577c73e2788b7eea8bebf9d700958db5475 100644 (file)
@@ -121,6 +121,8 @@ What's new
 
 - Fix crash when using inset-select-all in tabular.
 
+- Only allow toggling math limits when it makes sense.
+
 
 * INTERNALS