[LyX/master] Fix bug #11007
Enrico Forestieri
forenr at lyx.org
Sun Feb 28 21:38:02 UTC 2021
commit 52ce0ff49a0f9a5c33459428b2fdffa24febafce
Author: Enrico Forestieri <forenr at lyx.org>
Date: Sun Feb 28 22:32:11 2021 +0100
Fix bug #11007
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 | 5 ++++-
src/mathed/InsetMathColor.cpp | 9 ++++++++-
src/mathed/InsetMathColor.h | 4 ++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 1d492d2..6412c0e 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -1712,8 +1712,11 @@ void Cursor::handleNest(MathAtom const & a)
{
idx_type const idx = a.nucleus()->asNestInset()->firstIdx();
//lyxerr << "Cursor::handleNest: " << idx << 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(idx));
+ asArray(cap::grabAndEraseSelection(*this), t.nucleus()->cell(idx), f);
insert(t);
editInsertedInset();
}
diff --git a/src/mathed/InsetMathColor.cpp b/src/mathed/InsetMathColor.cpp
index 13e6fa4..be2c0f8 100644
--- a/src/mathed/InsetMathColor.cpp
+++ b/src/mathed/InsetMathColor.cpp
@@ -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);
diff --git a/src/mathed/InsetMathColor.h b/src/mathed/InsetMathColor.h
index d3ea050..c09e14a 100644
--- a/src/mathed/InsetMathColor.h
+++ b/src/mathed/InsetMathColor.h
@@ -34,6 +34,8 @@ public:
void draw(PainterInfo & pi, int x, int y) const override;
/// we need package color
void validate(LaTeXFeatures & features) const override;
+ /// we inherit the mode
+ mode_type currentMode() const override { return current_mode_; }
///
void write(TeXMathStream & os) const override;
/// 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_;
};
More information about the lyx-cvs
mailing list