X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathMacro.cpp;h=7670f487dba1e1867049535164a7fe9cb4d90610;hb=74f774d6cf18a897deb533d3afc697abb31f824e;hp=da22747ed881c7dce3da916ba727140e2eb53672;hpb=3e79e0f5f00add2c735d372f4734cf31f64b7e5f;p=lyx.git diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index da22747ed8..7670f487db 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -82,7 +82,8 @@ public: // macro arguments are in macros LATTEST(mathMacro_->nesting() > 0); /// The macro nesting can change display of insets. Change it locally. - Changer chg = make_change(mi.base.macro_nesting, mathMacro_->nesting()); + Changer chg = make_change(mi.base.macro_nesting, + mathMacro_->nesting() == 1 ? 0 : mathMacro_->nesting()); MathRow::Element e_beg(MathRow::BEG_ARG); e_beg.macro = mathMacro_; @@ -140,6 +141,15 @@ public: void htmlize(HtmlStream & ms) const { ms << mathMacro_->cell(idx_); } /// void octave(OctaveStream & os) const { os << mathMacro_->cell(idx_); } + /// + MathClass mathClass() const + { + return MC_UNKNOWN; + // This can be refined once the pointer issues are fixed. I did not + // notice any immediate crash with the following code, but it is risky + // nevertheless: + //return mathMacro_->cell(idx_).mathClass(); + } private: /// @@ -821,6 +831,26 @@ size_t MathMacro::appetite() const } +MathClass MathMacro::mathClass() const +{ + // This can be just a heuristic, since it is only considered for display + // when the macro is not linearised. Therefore it affects: + // * The spacing of the inset while being edited, + // * Intelligent splitting + // * Cursor word movement (Ctrl-Arrow). + if (MacroData const * m = macroBackup()) { + // If it is a global macro and is defined explicitly + if (m->symbol()) { + MathClass mc = string_to_class(m->symbol()->extra); + if (mc != MC_UNKNOWN) + return mc; + } + } + // Otherwise guess from the expanded macro + return d->expanded_.mathClass(); +} + + InsetMath::mode_type MathMacro::currentMode() const { // There is no way to guess the mode of user defined macros, so they are