]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathData.cpp
Assure correct spacing of colored items in mathed
[lyx.git] / src / mathed / MathData.cpp
index c3b3faa2395f38731b74031ca11dc9be3929047f..90f41eb242c89dd9391e4b0cf97e169c103302e1 100644 (file)
@@ -48,7 +48,7 @@ namespace lyx {
 
 MathData::MathData(Buffer * buf, const_iterator from, const_iterator to)
        : base_type(from, to), minasc_(0), mindes_(0), slevel_(0),
-         sshift_(0), kerning_(0), buffer_(buf)
+         sshift_(0), buffer_(buf)
 {}
 
 
@@ -267,18 +267,6 @@ bool isInside(DocIterator const & it, MathData const & ar,
 #endif
 
 
-int MathData::caretAscent(BufferView const * bv) const
-{
-       return mrow_cache_[bv].caret_ascent;
-}
-
-
-int MathData::caretDescent(BufferView const * bv) const
-{
-       return mrow_cache_[bv].caret_descent;
-}
-
-
 void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
 {
        frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
@@ -294,7 +282,6 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
 
        MathRow mrow(mi, this);
        mrow.metrics(mi, dim);
-       kerning_ = mrow.kerning(bv);
 
        // Set a minimal ascent/descent for the cell
        if (tight)
@@ -310,9 +297,14 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim, bool tight) const
        // so that we can set the caret vertical dimensions.
        mrow.caret_ascent = min(dim.asc, fm.maxAscent());
        mrow.caret_descent = min(dim.des, fm.maxDescent());
+       /// do the same for math cells linearized in the row
+       MathRow caret_row = MathRow(mrow.caret_ascent, mrow.caret_descent);
+       for (auto const & e : mrow)
+               if (e.type == MathRow::BEGIN && e.ar)
+                       bv->setMathRow(e.ar, caret_row);
 
        // Cache row and dimension.
-       mrow_cache_[bv] = mrow;
+       bv->setMathRow(this, mrow);
        bv->coordCache().arrays().add(this, dim);
 }
 
@@ -330,7 +322,7 @@ void MathData::drawSelection(PainterInfo & pi, int const x, int const y) const
        MathData const & c1 = inset->cell(s1.idx());
 
        if (s1.idx() == s2.idx() && &c1 == this) {
-               // selection indide cell
+               // selection inside cell
                Dimension const dim = bv->coordCache().getArrays().dim(&c1);
                int const beg = c1.pos2x(bv, s1.pos());
                int const end = c1.pos2x(bv, s2.pos());
@@ -357,7 +349,7 @@ void MathData::draw(PainterInfo & pi, int const x, int const y) const
        setXY(*pi.base.bv, x, y);
 
        drawSelection(pi, x, y);
-       MathRow const & mrow = mrow_cache_[pi.base.bv];
+       MathRow const & mrow = pi.base.bv->mathRow(this);
        mrow.draw(pi, x, y);
 }
 
@@ -388,12 +380,18 @@ void MathData::drawT(TextPainter & pain, int x, int y) const
 }
 
 
-void MathData::updateBuffer(ParIterator const & it, UpdateType utype)
+int MathData::kerning(BufferView const * bv) const
+{
+       return  bv->mathRow(this).kerning(bv);
+}
+
+
+void MathData::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
 {
        // pass down
        for (size_t i = 0, n = size(); i != n; ++i) {
                MathAtom & at = operator[](i);
-               at.nucleus()->updateBuffer(it, utype);
+               at.nucleus()->updateBuffer(it, utype, deleted);
        }
 }
 
@@ -968,6 +966,18 @@ MathClass MathData::mathClass() const
 }
 
 
+MathClass MathData::lastMathClass() const
+{
+       MathClass res = MC_ORD;
+       for (MathAtom const & at : *this) {
+               MathClass mc = at->mathClass();
+               if (mc != MC_UNKNOWN)
+                       return res = mc;
+       }
+       return res;
+}
+
+
 ostream & operator<<(ostream & os, MathData const & ar)
 {
        odocstringstream oss;