Selection snapping is now considering wrapping.

Thanks Alexander Rezinsky <alexrez@gmail.com> for mentioning this!
dev
Christoph Lohmann 2013-04-28 18:14:15 +02:00
parent a53017c8b4
commit 911ba5674b
1 changed files with 39 additions and 3 deletions

42
st.c
View File

@ -681,13 +681,49 @@ void
selsnap(int mode, int *x, int *y, int direction) { selsnap(int mode, int *x, int *y, int direction) {
switch(mode) { switch(mode) {
case SNAP_WORD: case SNAP_WORD:
while(*x > 0 && *x < term.col-1 for(;;) {
&& term.line[*y][*x + direction].c[0] != ' ') { 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; *x += direction;
} }
break; break;
case SNAP_LINE: case SNAP_LINE:
*x = (direction < 0) ? 0 : term.col - 1; *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; break;
default: default:
break; break;
@ -820,7 +856,7 @@ bpress(XEvent *e) {
sel.snap = 0; sel.snap = 0;
} }
selsnap(sel.snap, &sel.bx, &sel.by, -1); 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.x = sel.bx;
sel.b.y = sel.by; sel.b.y = sel.by;
sel.e.x = sel.ex; sel.e.x = sel.ex;