]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #11007
authorEnrico Forestieri <forenr@lyx.org>
Mon, 1 Mar 2021 09:38:02 +0000 (10:38 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 1 Mar 2021 09:38:02 +0000 (10:38 +0100)
The math color inset inherits the mode of the containing inset.
This mode is inferred by the kind of font in effect. Setting the
right mode allows to insert spaces where these should be allowed.
Another small glitch was that the selection was always parsed in
math mode, so that any space was swallowed, even if the inset would
allow them.

src/Cursor.cpp
src/mathed/InsetMathColor.cpp
src/mathed/InsetMathColor.h
status.23x

index 0963da63ecfa95cd22b358f596ab6782dcdf28f3..bdfba6114bc776d61b28fc196f6d4736bf54924a 100644 (file)
@@ -1556,8 +1556,11 @@ docstring Cursor::macroName()
 void Cursor::handleNest(MathAtom const & a, int c)
 {
        //lyxerr << "Cursor::handleNest: " << c << endl;
+       InsetMath const * im = selectionBegin().inset().asInsetMath();
+       Parse::flags const f = im && im->currentMode() != InsetMath::MATH_MODE
+               ? Parse::TEXTMODE : Parse::NORMAL;
        MathAtom t = a;
-       asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
+       asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(c), f);
        insert(t);
        posBackward();
        pushBackward(*nextInset());
index d665734b5182893b7a0da3a58e609bc59c79df12..f80895b3705672273e4b7db6fe9c9cce8548bac0 100644 (file)
@@ -36,7 +36,8 @@ InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle, ColorCode color)
 
 InsetMathColor::InsetMathColor(Buffer * buf, bool oldstyle,
                docstring const & color)
-       : InsetMathNest(buf, 1), oldstyle_(oldstyle), color_(color)
+       : InsetMathNest(buf, 1), oldstyle_(oldstyle), color_(color),
+         current_mode_(UNDECIDED_MODE)
 {}
 
 
@@ -48,12 +49,18 @@ Inset * InsetMathColor::clone() const
 
 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       current_mode_ = isTextFont(mi.base.fontname) ? TEXT_MODE : MATH_MODE;
+       Changer dummy = mi.base.changeEnsureMath(current_mode_);
+
        cell(0).metrics(mi, dim);
 }
 
 
 void InsetMathColor::draw(PainterInfo & pi, int x, int y) const
 {
+       current_mode_ = isTextFont(pi.base.fontname) ? TEXT_MODE : MATH_MODE;
+       Changer dummy = pi.base.changeEnsureMath(current_mode_);
+
        ColorCode origcol = pi.base.font.color();
        pi.base.font.setColor(lcolor.getFromLaTeXName(to_utf8(color_)));
        cell(0).draw(pi, x, y);
index 08495b364d76a83b1683c8f5ffcfd8de54b51cf5..d3098d95cea55c6fa5fc21fd1615d929a2957a88 100644 (file)
@@ -34,6 +34,8 @@ public:
        void draw(PainterInfo & pi, int x, int y) const;
        /// we need package color
        void validate(LaTeXFeatures & features) const;
+       /// we inherit the mode
+       mode_type currentMode() const override { return current_mode_; }
        ///
        void write(WriteStream & os) const;
        /// FIXME XHTML For now, we do nothing with color.
@@ -53,6 +55,8 @@ private:
        bool oldstyle_;
        /// Our color. Only valid LaTeX colors are allowed.
        docstring color_;
+       /// the inherited mode
+       mutable mode_type current_mode_;
 };
 
 
index 82253efe27f7f220703425c84a49feb0855e25be..0120c499ee577b6c12675d973eb5bb04b1c538af 100644 (file)
@@ -90,6 +90,8 @@ What's new
 
 - On screen, show upper case greek letters in \mathbf as bold (bug 3751).
 
+- Fix coloring of text-mode material in math equations (bug 11007).
+
 
 * INTERNALS