[dev] [PATCH 7/7] Simplify selsnap and selnormalize.

From: noname <noname_AT_inventati.org>
Date: Fri, 1 May 2015 02:22:45 +0000

Use selsnap only for SNAP_WORD case.
---
 st.c | 96 ++++++++++++++++++++++++++++----------------------------------------
 1 file changed, 40 insertions(+), 56 deletions(-)
diff --git a/st.c b/st.c
index ac3c9f1..43fdbb3 100644
--- a/st.c
+++ b/st.c
_AT_@ -693,8 +693,19 @@ selnormalize(void) {
 	sel.nb.y = MIN(sel.ob.y, sel.oe.y);
 	sel.ne.y = MAX(sel.ob.y, sel.oe.y);
 
-	selsnap(&sel.nb.x, &sel.nb.y, -1);
-	selsnap(&sel.ne.x, &sel.ne.y, +1);
+	if(sel.snap == SNAP_WORD) {
+		selsnap(&sel.nb.x, &sel.nb.y, -1);
+		selsnap(&sel.ne.x, &sel.ne.y, +1);
+	} else if(sel.snap == SNAP_LINE) {
+		sel.nb.x = 0;
+		sel.ne.x = term.col - 1;
+		for(; sel.nb.y > 0; sel.nb.y--)
+			if(!(term.line[sel.nb.y-1][term.col-1].mode & ATTR_WRAP))
+				break;
+		for(; sel.ne.y < term.row-1; sel.ne.y++)
+			if(!(term.line[sel.ne.y  ][term.col-1].mode & ATTR_WRAP))
+				break;
+	}
 
 	/* expand selection over line breaks */
 	if(sel.type == SEL_REGULAR) {
_AT_@ -723,64 +734,37 @@ selsnap(int *x, int *y, int direction) {
 	bool delim;
 	Glyph *gp, *prevgp;
 
-	switch(sel.snap) {
-	case SNAP_WORD:
-		/*
-		 * Snap around if the word wraps around at the end or
-		 * beginning of a line.
-		 */
-		prevgp = &term.line[*y][*x];
-		for(;;) {
-			newx = *x + direction;
-			newy = *y;
-			if(!BETWEEN(newx, 0, term.col - 1)) {
-				newy += direction;
-				newx = (newx + term.col) % term.col;
-				if (!BETWEEN(newy, 0, term.row - 1))
-					break;
-
-				yt = direction > 0 ? *y : newy;
-				if(!(term.line[yt][term.col-1].mode & ATTR_WRAP))
-					break;
-			}
-
-			if (newx >= tlinelen(newy))
+	/*
+	 * Snap around if the word wraps around at the end or
+	 * beginning of a line.
+	 */
+	prevgp = &term.line[*y][*x];
+	for(;;) {
+		newx = *x + direction;
+		newy = *y;
+		if(!BETWEEN(newx, 0, term.col - 1)) {
+			newy += direction;
+			newx = (newx + term.col) % term.col;
+			if (!BETWEEN(newy, 0, term.row - 1))
 				break;
 
-			gp = &term.line[newy][newx];
-			delim = ISDELIM(gp->u);
-			if(!(gp->mode & ATTR_WDUMMY) && (delim != ISDELIM(prevgp->u)
-					|| (delim && gp->u != prevgp->u)))
+			yt = direction > 0 ? *y : newy;
+			if(!(term.line[yt][term.col-1].mode & ATTR_WRAP))
 				break;
-
-			*x = newx;
-			*y = newy;
-			prevgp = gp;
-		}
-		break;
-	case SNAP_LINE:
-		/*
-		 * Snap around if the the previous line or the current one
-		 * has set ATTR_WRAP at its end. Then the whole next or
-		 * previous line will be selected.
-		 */
-		*x = (direction < 0) ? 0 : term.col - 1;
-		if(direction < 0) {
-			for(; *y > 0; *y += direction) {
-				if(!(term.line[*y-1][term.col-1].mode
-						& ATTR_WRAP)) {
-					break;
-				}
-			}
-		} else if(direction > 0) {
-			for(; *y < term.row-1; *y += direction) {
-				if(!(term.line[*y][term.col-1].mode
-						& ATTR_WRAP)) {
-					break;
-				}
-			}
 		}
-		break;
+
+		if (newx >= tlinelen(newy))
+			break;
+
+		gp = &term.line[newy][newx];
+		delim = ISDELIM(gp->u);
+		if(!(gp->mode & ATTR_WDUMMY) && (delim != ISDELIM(prevgp->u)
+				|| (delim && gp->u != prevgp->u)))
+			break;
+
+		*x = newx;
+		*y = newy;
+		prevgp = gp;
 	}
 }
 
-- 
1.8.4
Received on Fri May 01 2015 - 04:22:45 CEST

This archive was generated by hypermail 2.3.0 : Fri May 01 2015 - 04:24:17 CEST