[dev] [PATCH 10/10] Fix empty selection highlighting bug.

From: noname <noname_AT_inventati.org>
Date: Sun, 3 May 2015 19:28:10 +0000

When user clicks LMB, one character is selected, but will not be copied
to selection until the user moves cursor a bit. Therefore, the character
should not be highlighted as selected yet.

Before the patch, the trick was not to mark line as dirty to avoid
highlighting it. However, if user has already selected something and
clicks in line that contains selection, selclear sets the line as dirty
and one character is highlighted when it should not.

This patch replaces dirty trick with explicit check for sel.mode inside
selected().
---
 st.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/st.c b/st.c
index e30f111..f677e24 100644
--- a/st.c
+++ b/st.c
_AT_@ -725,6 +725,9 @@ selnormalize(void) {
 
 bool
 selected(int x, int y) {
+	if(sel.mode == SEL_EMPTY)
+		return false;
+
 	if(sel.type == SEL_RECTANGULAR)
 		return BETWEEN(y, sel.nb.y, sel.ne.y)
 		    && BETWEEN(x, sel.nb.x, sel.ne.x);
_AT_@ -898,14 +901,9 @@ bpress(XEvent *e) {
 		}
 		selnormalize();
 
-		/*
-		 * Draw selection, unless it's regular and we don't want to
-		 * make clicks visible
-		 */
-		if(sel.snap != 0) {
+		if(sel.snap != 0)
 			sel.mode = SEL_READY;
-			tsetdirt(sel.nb.y, sel.ne.y);
-		}
+		tsetdirt(sel.nb.y, sel.ne.y);
 		sel.tclick2 = sel.tclick1;
 		sel.tclick1 = now;
 	}
-- 
1.8.4
Received on Sun May 03 2015 - 21:28:10 CEST

This archive was generated by hypermail 2.3.0 : Sun May 03 2015 - 21:36:07 CEST