as the subject says, i am trying to change the color of selected text in
mathed
attached the approach thing i am taking atm, which basically amounts to
checking whether an element is spanned by a selection and changing the
font color if appropriate.
i have some questions for those of you (andre?) who know mathed intimately.
for the moment i am having a number of troubles which are related (i
think) to the fact that i do not know idx (cell) and pos for mathdata
and mathinset. am i overseeing something? if not, any suggestions for an
elegant solution?
finally, i seem to need to touch a lot of drawing methods. is there a
way to avoid this?
thanks, edwin
Index: src/mathed/InsetMathSymbol.cpp
===================================================================
--- src/mathed/InsetMathSymbol.cpp (revision 24061)
+++ src/mathed/InsetMathSymbol.cpp (working copy)
@@ -12,6 +12,8 @@
#include "InsetMathSymbol.h"
+#include "BufferView.h"
+#include "Cursor.h"
#include "Dimension.h"
#include "LaTeXFeatures.h"
#include "MathAtom.h"
@@ -97,7 +99,17 @@
else
x += static_cast<int>(0.0833*em+0.5);
+
FontSetChanger dummy(pi.base, sym_->inset.c_str());
+ // selected?
+ Cursor & cur = pi.base.bv->cursor();
+ idx_type const cell0 = cur.selBegin().idx();
+ idx_type const cell1 = cur.selEnd().idx();
+ pos_type const pos0 = cur.selBegin().pos();
+ pos_type const pos1 = cur.selEnd().pos();
+ bool selection = (pos0 != pos1 && cell1 == cell0);
+ pi.base.font.setColor(selection ? Color_selectiontext : Color_math);
+
pi.draw(x, y - h_, sym_->draw);
}
Index: src/mathed/MathData.cpp
===================================================================
--- src/mathed/MathData.cpp (revision 24061)
+++ src/mathed/MathData.cpp (working copy)
@@ -313,9 +313,17 @@
inlineCompletionData = &inlineCompletionPos.cell();
CoordCacheBase<Inset> & coords = pi.base.bv->coordCache().insets();
+ Cursor & cur = pi.base.bv->cursor();
+ idx_type const cell0 = cur.selBegin().idx();
+ idx_type const cell1 = cur.selEnd().idx();
+ pos_type const pos0 = cur.selBegin().pos();
+ pos_type const pos1 = cur.selEnd().pos();
for (size_t i = 0, n = size(); i != n; ++i) {
MathAtom const & at = operator[](i);
coords.add(at.nucleus(), x, y);
+ bool selection = (pos0 != pos1
+ && cell1 == cell0 && i >= pos0 && i < pos1);
+ pi.base.font.setColor(selection ? Color_selectiontext : Color_math);
at->drawSelection(pi, x, y);
at->draw(pi, x, y);
x += coords.dim(at.nucleus()).wid;
@@ -328,7 +336,7 @@
if (completion.length() == 0)
continue;
FontInfo f = pi.base.font;
-
+
// draw the unique and the non-unique completion part
// Note: this is not time-critical as it is
// only done once per screen.
Index: src/mathed/MathData.h
===================================================================
--- src/mathed/MathData.h (revision 24061)
+++ src/mathed/MathData.h (working copy)
@@ -167,7 +167,7 @@
mutable int slevel_;
mutable int sshift_;
mutable int kerning_;
-
+
private:
/// is this an exact match at this position?
bool find1(MathData const & ar, size_type pos) const;