mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Use Color_selectiontext as needed for partial selection in math
Currently, selected math hull insets use Color_selectiontext when system colors are in use. This commit implements the same behavior for partial selection. This is done by introducing two element types (BEGIN_SEL and END_SEL) to MathRow.
This commit is contained in:
parent
73e588bd44
commit
65cb9fa4df
@ -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;
|
||||
}
|
||||
|
@ -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 << "<sel>";
|
||||
break;
|
||||
case MathRow::END_SEL:
|
||||
os << "</sel>" ;
|
||||
break;
|
||||
case MathRow::BOX:
|
||||
os << "<" << e.before << "-[]-" << e.after << ">";
|
||||
break;
|
||||
|
@ -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)
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user