[dev] [PATCH v2] Fix selection clearing

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Sun, 23 Jun 2013 12:58:22 +0200

From: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>

The way st knows if there is a selection activated is checking if sel.ob.x
is equal to -1. In some parts of the code the way of disabling the selection
was only setting it to -1, but after it you can't be sure if the selection
is clearing from the terminal representation, because it is necessary mark
all the lines affected by the selection as dirty. Already there is a functon
which perform this task, selclear.
---
 st.c |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/st.c b/st.c
index b9caeca..2bd98c0 100644
--- a/st.c
+++ b/st.c
_AT_@ -899,11 +899,7 @@ bpress(XEvent *e) {
 		gettimeofday(&now, NULL);
 
 		/* Clear previous selection, logically and visually. */
-		if(sel.ob.x != -1) {
-			sel.ob.x = -1;
-			tsetdirt(sel.nb.y, sel.ne.y);
-			draw();
-		}
+		selclear(NULL);
 		sel.mode = 1;
 		sel.type = SEL_REGULAR;
 		sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
_AT_@ -1119,7 +1115,7 @@ brelease(XEvent *e) {
 		selpaste(NULL);
 	} else if(e->xbutton.button == Button1) {
 		if(sel.mode < 2) {
-			sel.ob.x = -1;
+			selclear(NULL);
 		} else {
 			getbuttoninfo(e);
 			selcopy();
_AT_@ -1545,7 +1541,7 @@ selscroll(int orig, int n) {
 
 	if(BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) {
 		if((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) {
-			sel.ob.x = -1;
+			selclear(NULL);
 			return;
 		}
 		if(sel.type == SEL_RECTANGULAR) {
_AT_@ -2055,7 +2051,7 @@ csihandle(void) {
 			tputtab(1);
 		break;
 	case 'J': /* ED -- Clear screen */
-		sel.ob.x = -1;
+		selclear(NULL);
 		switch(csiescseq.arg[0]) {
 		case 0: /* below */
 			tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
_AT_@ -2552,7 +2548,7 @@ tputc(char *c, int len) {
 	if(control && !(term.c.attr.mode & ATTR_GFX))
 		return;
 	if(sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y))
-		sel.ob.x = -1;
+		selclear(NULL);
 	if(IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) {
 		term.line[term.c.y][term.c.x].mode |= ATTR_WRAP;
 		tnewline(1);
-- 
1.7.10.4
Received on Sun Jun 23 2013 - 12:58:22 CEST

This archive was generated by hypermail 2.3.0 : Sun Jun 23 2013 - 13:00:07 CEST