[dev] [st] [PATCH] Allow selecting single character.

From: Alexander Sedov <alex0player_AT_gmail.com>
Date: Thu, 25 Apr 2013 03:02:46 +0400

Previously, when releasing Button 1, if only single character was
selected, selection was silently cleared. This is no longer the case with
this patch, which ensures more intuitive handling of this situation, while
still providing a way of clearing selection.
---
 st.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/st.c b/st.c
index b0d0cb0..58e9b1b 100644
--- a/st.c
+++ b/st.c
_AT_@ -138,6 +138,11 @@ enum selection_type {
 	SEL_RECTANGULAR = 2
 };
 
+enum selection_mode {
+	SEL_START = 1,
+	SEL_ACTIVE = 2
+};
+
 enum selection_snap {
 	SNAP_WORD = 1,
 	SNAP_LINE = 2
_AT_@ -689,6 +694,7 @@ getbuttoninfo(XEvent *e) {
 	int type;
 	uint state = e->xbutton.state &~Button1Mask;
 
+	sel.mode = SEL_ACTIVE;
 	sel.alt = IS_SET(MODE_ALTSCREEN);
 
 	sel.ex = x2col(e->xbutton.x);
_AT_@ -779,7 +785,7 @@ bpress(XEvent *e) {
 			tsetdirt(sel.b.y, sel.e.y);
 			draw();
 		}
-		sel.mode = 1;
+		sel.mode = SEL_START;
 		sel.type = SEL_REGULAR;
 		sel.ex = sel.bx = x2col(e->xbutton.x);
 		sel.ey = sel.by = y2row(e->xbutton.y);
_AT_@ -806,10 +812,11 @@ bpress(XEvent *e) {
 		sel.e.y = sel.ey;
 
 		/*
-		 * Draw selection, unless it's regular and we don't want to
-		 * make clicks visible
+		 * Draw selection, unless it's regular and it is unclear
+		 * if user intended to select or merely clicked
 		 */
 		if (sel.snap != 0) {
+			sel.mode = SEL_ACTIVE;
 			tsetdirt(sel.b.y, sel.e.y);
 			draw();
 		}
_AT_@ -987,14 +994,14 @@ brelease(XEvent *e) {
 	if(e->xbutton.button == Button2) {
 		selpaste(NULL);
 	} else if(e->xbutton.button == Button1) {
-		sel.mode = 0;
-		getbuttoninfo(e);
-		term.dirty[sel.ey] = 1;
-		if(sel.bx == sel.ex && sel.by == sel.ey) {
+		if(sel.mode == SEL_START) {
 			sel.bx = -1;
 		} else {
+			getbuttoninfo(e);
 			selcopy();
 		}
+		sel.mode = 0;
+		term.dirty[sel.ey] = 1;
 	}
 }
 
-- 
1.7.10.4
Received on Thu Apr 25 2013 - 01:02:46 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 25 2013 - 01:12:05 CEST