aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2013-04-28 18:14:15 +0200
committerChristoph Lohmann <20h@r-36.net>2013-04-28 18:14:15 +0200
commit911ba5674bc4eb53a2ed548856a50032c39ca7f2 (patch)
tree3b9f17e8a1e5ea451dfcac44ad6092f07de584a8
parenta53017c8b47f511cf0462ac910cf9223a31ceb2f (diff)
downloadst-patched-911ba5674bc4eb53a2ed548856a50032c39ca7f2.tar.bz2
st-patched-911ba5674bc4eb53a2ed548856a50032c39ca7f2.tar.xz
st-patched-911ba5674bc4eb53a2ed548856a50032c39ca7f2.zip
Selection snapping is now considering wrapping.
Thanks Alexander Rezinsky <alexrez@gmail.com> for mentioning this!
-rw-r--r--st.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/st.c b/st.c
index aa2cd08..5095315 100644
--- a/st.c
+++ b/st.c
@@ -681,13 +681,49 @@ void
681selsnap(int mode, int *x, int *y, int direction) { 681selsnap(int mode, int *x, int *y, int direction) {
682 switch(mode) { 682 switch(mode) {
683 case SNAP_WORD: 683 case SNAP_WORD:
684 while(*x > 0 && *x < term.col-1 684 for(;;) {
685 && term.line[*y][*x + direction].c[0] != ' ') { 685 if(direction < 0 && *x <= 0) {
686 if(*y > 0 && term.line[*y - 1][term.col-1].mode
687 & ATTR_WRAP) {
688 *y -= 1;
689 *x = term.col-1;
690 } else {
691 break;
692 }
693 }
694 if(direction > 0 && *x >= term.col-1) {
695 if(*y < term.row-1 && term.line[*y][*x].mode
696 & ATTR_WRAP) {
697 *y += 1;
698 *x = 0;
699 } else {
700 break;
701 }
702 }
703
704 if(term.line[*y][*x + direction].c[0] == ' ')
705 break;
706
686 *x += direction; 707 *x += direction;
687 } 708 }
688 break; 709 break;
689 case SNAP_LINE: 710 case SNAP_LINE:
690 *x = (direction < 0) ? 0 : term.col - 1; 711 *x = (direction < 0) ? 0 : term.col - 1;
712 if(direction < 0 && *y > 0) {
713 for(; *y > 0; *y += direction) {
714 if(!(term.line[*y-1][term.col-1].mode
715 & ATTR_WRAP)) {
716 break;
717 }
718 }
719 } else if(direction > 0 && *y < term.row-1) {
720 for(; *y < term.row; *y += direction) {
721 if(!(term.line[*y][term.col-1].mode
722 & ATTR_WRAP)) {
723 break;
724 }
725 }
726 }
691 break; 727 break;
692 default: 728 default:
693 break; 729 break;
@@ -820,7 +856,7 @@ bpress(XEvent *e) {
820 sel.snap = 0; 856 sel.snap = 0;
821 } 857 }
822 selsnap(sel.snap, &sel.bx, &sel.by, -1); 858 selsnap(sel.snap, &sel.bx, &sel.by, -1);
823 selsnap(sel.snap, &sel.ex, &sel.ey, 1); 859 selsnap(sel.snap, &sel.ex, &sel.ey, +1);
824 sel.b.x = sel.bx; 860 sel.b.x = sel.bx;
825 sel.b.y = sel.by; 861 sel.b.y = sel.by;
826 sel.e.x = sel.ex; 862 sel.e.x = sel.ex;