Abdel wrote:
> You should use Row::sel_beg and Row::sel_end instead of 
> cursor().selBegin().pos() and cursor().selEnd().pos().

thanks. the attached *almost* works, but the text in the whole row where the 
selection starts/ends ends up being marked as selected (hope i am clear). 
haven't been able to find out why...



Index: src/Color.cpp
===================================================================
--- src/Color.cpp	(revision 24016)
+++ 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 24016)
+++ 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 24016)
+++ src/rowpainter.cpp	(working copy)
@@ -243,13 +243,22 @@
 			c = '(';
 		str[0] = par_.transformChar(c, pos);
 	}
-
+	// selected text?
+	pit_type const p0 = pi_.base.bv->cursor().selBegin().pit();
+	pit_type const p1 = pi_.base.bv->cursor().selEnd().pit();
+	bool selection = row_.sel_beg != row_.sel_end && ((pit_ > p0 && pit_ < p1)
+		|| (pit_ == p0 && pos > row_.sel_beg) 
+		|| (pit_ == p1 && pos < row_.sel_end));
 	// 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 (row_.sel_beg != row_.sel_end && (pit_ == p0 && pos == row_.sel_beg 
+			|| pit_ == p1 && pos == row_.sel_end))
+			break;
+
 		if (prev_change != par_.lookupChange(pos).type)
 			break;
 
@@ -299,9 +308,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);

Reply via email to