[hackers] [st] Selection snapping is now considering wrapping. || Christoph Lohmann

From: <git_AT_suckless.org>
Date: Sun, 28 Apr 2013 18:16:55 +0200

commit 911ba5674bc4eb53a2ed548856a50032c39ca7f2
Author: Christoph Lohmann <20h_AT_r-36.net>
Date: Sun Apr 28 18:14:15 2013 +0200

    Selection snapping is now considering wrapping.
    
    Thanks Alexander Rezinsky <alexrez_AT_gmail.com> for mentioning this!

diff --git a/st.c b/st.c
index aa2cd08..5095315 100644
--- a/st.c
+++ b/st.c
_AT_@ -681,13 +681,49 @@ void
 selsnap(int mode, int *x, int *y, int direction) {
         switch(mode) {
         case SNAP_WORD:
- while(*x > 0 && *x < term.col-1
- && term.line[*y][*x + direction].c[0] != ' ') {
+ for(;;) {
+ if(direction < 0 && *x <= 0) {
+ if(*y > 0 && term.line[*y - 1][term.col-1].mode
+ & ATTR_WRAP) {
+ *y -= 1;
+ *x = term.col-1;
+ } else {
+ break;
+ }
+ }
+ if(direction > 0 && *x >= term.col-1) {
+ if(*y < term.row-1 && term.line[*y][*x].mode
+ & ATTR_WRAP) {
+ *y += 1;
+ *x = 0;
+ } else {
+ break;
+ }
+ }
+
+ if(term.line[*y][*x + direction].c[0] == ' ')
+ break;
+
                         *x += direction;
                 }
                 break;
         case SNAP_LINE:
                 *x = (direction < 0) ? 0 : term.col - 1;
+ if(direction < 0 && *y > 0) {
+ for(; *y > 0; *y += direction) {
+ if(!(term.line[*y-1][term.col-1].mode
+ & ATTR_WRAP)) {
+ break;
+ }
+ }
+ } else if(direction > 0 && *y < term.row-1) {
+ for(; *y < term.row; *y += direction) {
+ if(!(term.line[*y][term.col-1].mode
+ & ATTR_WRAP)) {
+ break;
+ }
+ }
+ }
                 break;
         default:
                 break;
_AT_@ -820,7 +856,7 @@ bpress(XEvent *e) {
                         sel.snap = 0;
                 }
                 selsnap(sel.snap, &sel.bx, &sel.by, -1);
- selsnap(sel.snap, &sel.ex, &sel.ey, 1);
+ selsnap(sel.snap, &sel.ex, &sel.ey, +1);
                 sel.b.x = sel.bx;
                 sel.b.y = sel.by;
                 sel.e.x = sel.ex;
Received on Sun Apr 28 2013 - 18:16:55 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 28 2013 - 18:24:10 CEST