diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index a92511919a..eee53d2f50 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -229,6 +229,18 @@ bool MathData::addToMathRow(MathRow & mrow, MetricsInfo & mi) const ar->updateMacros(&bv->cursor(), mi.macrocontext, InternalUpdate, mi.base.macro_nesting); + pos_type bspos = -1, espos = -1; + Cursor const & cur = bv->cursor(); + InsetMath const * inset = cur.inset().asInsetMath(); + if (cur.selection() && inset) { + CursorSlice const s1 = cur.selBegin(); + CursorSlice const s2 = cur.selEnd(); + // Detect inner selection in this math data. + if (s1.idx() == s2.idx() && &inset->cell(s1.idx()) == this) { + bspos = s1.pos(); + espos = s2.pos(); + } + } // FIXME: for completion, try to insert the relevant data in the // mathrow (like is done for text rows). We could add a pair of @@ -240,11 +252,15 @@ bool MathData::addToMathRow(MathRow & mrow, MetricsInfo & mi) const size_t const compl_pos = has_completion ? inlineCompletionPos.pos() : 0; for (size_t i = 0 ; i < size() ; ++i) { + if (i == bspos) + mrow.push_back(MathRow::Element(mi, MathRow::BEGIN_SEL)); has_contents |= (*this)[i]->addToMathRow(mrow, mi); if (i + 1 == compl_pos) { mrow.back().compl_text = bv->inlineCompletion(); mrow.back().compl_unique_to = bv->inlineCompletionUniqueChars(); } + if (i + 1 == espos) + mrow.push_back(MathRow::Element(mi, MathRow::END_SEL)); } return has_contents; } diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp index 81b6ad9e92..fee869c89a 100644 --- a/src/mathed/MathRow.cpp +++ b/src/mathed/MathRow.cpp @@ -18,6 +18,7 @@ #include "BufferView.h" #include "ColorSet.h" #include "CoordCache.h" +#include "LyXRC.h" #include "MetricsInfo.h" #include "mathed/InsetMath.h" @@ -247,6 +248,8 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) Dimension d; switch (e.type) { case DUMMY: + case BEGIN_SEL: + case END_SEL: break; case INSET: e.inset->metrics(mi, d); @@ -315,6 +318,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) void MathRow::draw(PainterInfo & pi, int x, int const y) const { + Changer change_color; CoordCache & coords = pi.base.bv->coordCache(); for (Element const & e : elements_) { switch (e.type) { @@ -351,6 +355,13 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) const e.inset->afterDraw(pi); x += e.before + e.after; break; + case BEGIN_SEL: + if (lyxrc.use_system_colors) + change_color = pi.base.font.changeColor(Color_selectiontext); + break; + case END_SEL: + change_color = noChange(); + break; case BOX: { if (e.color == Color_none) break; @@ -424,6 +435,12 @@ ostream & operator<<(ostream & os, MathRow::Element const & e) if (e.inset) os << "]"; break; + case MathRow::BEGIN_SEL: + os << ""; + break; + case MathRow::END_SEL: + os << "" ; + break; case MathRow::BOX: os << "<" << e.before << "-[]-" << e.after << ">"; break; diff --git a/src/mathed/MathRow.h b/src/mathed/MathRow.h index 9efab92e85..2678ac4e23 100644 --- a/src/mathed/MathRow.h +++ b/src/mathed/MathRow.h @@ -50,6 +50,8 @@ public: BOX, // an empty box BEGIN, // an inset and/or a math array begins here END, // an inset and/or a math array ends here + BEGIN_SEL, // the selection begins here + END_SEL, // the selection ends here DUMMY // a dummy element (used before or after row) };