i am trying to get a different text color in a selection (not very
succesfully up until now) and have the attached code which only changes
some color settings in rowpainter
now the odd thing is that if i start selecting regular text, the cells
in (an adjacent) tabular are also updated. and selecting text in a
tabular cell updates other regular text. usually this is not visible,
but since the colors are changed this now turns up.
somehow this smells like a bug. am i right?
edwin
PS tips to get the code working are welcome!
Index: src/Color.cpp
===================================================================
--- src/Color.cpp (revision 23989)
+++ src/Color.cpp (working copy)
@@ -102,6 +102,8 @@
{ Color_background, N_("background"), "background", "linen", "background" },
{ Color_foreground, N_("text"), "foreground", "black", "foreground" },
{ Color_selection, N_("selection"), "selection", "LightBlue", "selection" },
+ { Color_selectiontext, N_("selected text"),
+ "selectiontext", "white", "selectiontext" },
{ Color_latex, N_("LaTeX text"), "latex", "DarkRed", "latex" },
{ Color_inlinecompletion, N_("inline completion"),
"inlinecompletion", "grey60", "inlinecompletion" },
Index: src/ColorCode.h
===================================================================
--- src/ColorCode.h (revision 23989)
+++ src/ColorCode.h (working copy)
@@ -44,6 +44,8 @@
Color_foreground,
/// Background color of selected text
Color_selection,
+ /// Foreground color of selected text
+ Color_selectiontext,
/// Text color in LaTeX mode
Color_latex,
/// The color used for previews
Index: src/rowpainter.cpp
===================================================================
--- src/rowpainter.cpp (revision 23989)
+++ src/rowpainter.cpp (working copy)
@@ -244,12 +244,22 @@
str[0] = par_.transformChar(c, pos);
}
+ bool selection_ = false;
// collect as much similar chars as we can
for (++vpos ; vpos < end ; ++vpos) {
pos = bidi_.vis2log(vpos);
if (pos < font_span.first || pos > font_span.last)
break;
+ if (pos == pi_.base.bv->cursor().selBegin().pos()) {
+ selection_ = false;
+ break;
+ }
+ if (pos == pi_.base.bv->cursor().selEnd().pos()) {
+ selection_ = true;
+ break;
+ }
+
if (prev_change != par_.lookupChange(pos).type)
break;
@@ -299,9 +309,11 @@
docstring s(&str[0], str.size());
- if (prev_change != Change::UNCHANGED) {
+ if (selection_ || prev_change != Change::UNCHANGED) {
FontInfo copy = font;
- if (prev_change == Change::DELETED) {
+ if (selection_) {
+ copy.setColor(Color_selectiontext);
+ } else if (prev_change == Change::DELETED) {
copy.setColor(Color_deletedtext);
} else if (prev_change == Change::INSERTED) {
copy.setColor(Color_addedtext);