From: Jean-Marc Lasgouttes Date: Mon, 3 Sep 2018 15:49:54 +0000 (+0200) Subject: Allow toggling (no)limits only after mathop symbol X-Git-Tag: 2.3.3~59 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=85e693806e206b24e9fd7d010368fba36a2b9710;p=features.git Allow toggling (no)limits only after mathop symbol 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) --- diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index 908a887eeb..1262370953 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -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; } diff --git a/src/mathed/InsetMathDecoration.h b/src/mathed/InsetMathDecoration.h index 9e58065ee3..a5d5e9c9b8 100644 --- a/src/mathed/InsetMathDecoration.h +++ b/src/mathed/InsetMathDecoration.h @@ -38,6 +38,8 @@ public: /// void infoize(odocstream & os) const; /// + MathClass mathClass() const; + /// bool isScriptable() const; /// void validate(LaTeXFeatures & features) const; diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index 57f3b87f88..315637c2da 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -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; } diff --git a/src/mathed/InsetMathScript.h b/src/mathed/InsetMathScript.h index 0b96d03ce2..51c8a2f710 100644 --- a/src/mathed/InsetMathScript.h +++ b/src/mathed/InsetMathScript.h @@ -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. diff --git a/status.23x b/status.23x index 07e2adcb04..c35e9577c7 100644 --- a/status.23x +++ b/status.23x @@ -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