aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColona <colona@ycc.fr>2014-06-03 04:34:58 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2014-06-04 21:09:07 +0200
commit2323e962e6bcddba42fd8be977088fb63ed8844c (patch)
tree32c6e165073c6eea809919272c0226cc014e5063
parentc6fcb78b3a9a73b691875048848430c18870a0fc (diff)
downloadst-2323e962e6bcddba42fd8be977088fb63ed8844c.tar.gz
st-2323e962e6bcddba42fd8be977088fb63ed8844c.zip
Make selection consistent over line breaks.
Currently, selection is expanded to the end of the line over line breaks only in regular selection mode, when the line in not empty and when going down and/or right. This covers all the cases including word selection mode, with the exception of rectangular selection because it would make this mode too rigid. This adjustment is made in selsort so I renamed it to selnormalize to better reflect what it does now. Signed-off-by: Roberto E. Vargas Caballero <k0ga@shike2.com>
-rw-r--r--st.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/st.c b/st.c
index 11d01df..9a41c5b 100644
--- a/st.c
+++ b/st.c
@@ -441,7 +441,7 @@ static void selclear(XEvent *);
441static void selrequest(XEvent *); 441static void selrequest(XEvent *);
442 442
443static void selinit(void); 443static void selinit(void);
444static void selsort(void); 444static void selnormalize(void);
445static inline bool selected(int, int); 445static inline bool selected(int, int);
446static char *getsel(void); 446static char *getsel(void);
447static void selcopy(void); 447static void selcopy(void);
@@ -657,8 +657,19 @@ y2row(int y) {
657 return LIMIT(y, 0, term.row-1); 657 return LIMIT(y, 0, term.row-1);
658} 658}
659 659
660static int tlinelen(int y) {
661 int i = term.col;
662
663 while (i > 0 && term.line[y][i - 1].c[0] == ' ')
664 --i;
665
666 return i;
667}
668
660static void 669static void
661selsort(void) { 670selnormalize(void) {
671 int i;
672
662 if(sel.ob.y == sel.oe.y) { 673 if(sel.ob.y == sel.oe.y) {
663 sel.nb.x = MIN(sel.ob.x, sel.oe.x); 674 sel.nb.x = MIN(sel.ob.x, sel.oe.x);
664 sel.ne.x = MAX(sel.ob.x, sel.oe.x); 675 sel.ne.x = MAX(sel.ob.x, sel.oe.x);
@@ -668,6 +679,15 @@ selsort(void) {
668 } 679 }
669 sel.nb.y = MIN(sel.ob.y, sel.oe.y); 680 sel.nb.y = MIN(sel.ob.y, sel.oe.y);
670 sel.ne.y = MAX(sel.ob.y, sel.oe.y); 681 sel.ne.y = MAX(sel.ob.y, sel.oe.y);
682
683 /* expand selection over line breaks */
684 if (sel.type == SEL_RECTANGULAR)
685 return;
686 i = tlinelen(sel.nb.y);
687 if (i < sel.nb.x)
688 sel.nb.x = i;
689 if (tlinelen(sel.ne.y) <= sel.ne.x)
690 sel.ne.x = term.col - 1;
671} 691}
672 692
673static inline bool 693static inline bool
@@ -683,8 +703,6 @@ selected(int x, int y) {
683 703
684void 704void
685selsnap(int mode, int *x, int *y, int direction) { 705selsnap(int mode, int *x, int *y, int direction) {
686 int i;
687
688 switch(mode) { 706 switch(mode) {
689 case SNAP_WORD: 707 case SNAP_WORD:
690 /* 708 /*
@@ -716,7 +734,7 @@ selsnap(int mode, int *x, int *y, int direction) {
716 continue; 734 continue;
717 } 735 }
718 736
719 if(strchr(worddelimiters, 737 if(*x >= tlinelen(*y) || strchr(worddelimiters,
720 term.line[*y][*x+direction].c[0])) { 738 term.line[*y][*x+direction].c[0])) {
721 break; 739 break;
722 } 740 }
@@ -747,18 +765,6 @@ selsnap(int mode, int *x, int *y, int direction) {
747 } 765 }
748 } 766 }
749 break; 767 break;
750 default:
751 /*
752 * Select the whole line when the end of line is reached.
753 */
754 if(direction > 0) {
755 i = term.col;
756 while(--i > 0 && term.line[*y][i].c[0] == ' ')
757 /* nothing */;
758 if(i > 0 && i < *x)
759 *x = term.col - 1;
760 }
761 break;
762 } 768 }
763} 769}
764 770
@@ -780,7 +786,7 @@ getbuttoninfo(XEvent *e) {
780 selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1); 786 selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1);
781 selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1); 787 selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1);
782 } 788 }
783 selsort(); 789 selnormalize();
784 790
785 sel.type = SEL_REGULAR; 791 sel.type = SEL_REGULAR;
786 for(type = 1; type < LEN(selmasks); ++type) { 792 for(type = 1; type < LEN(selmasks); ++type) {
@@ -896,7 +902,7 @@ bpress(XEvent *e) {
896 } 902 }
897 selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1); 903 selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
898 selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1); 904 selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
899 selsort(); 905 selnormalize();
900 906
901 /* 907 /*
902 * Draw selection, unless it's regular and we don't want to 908 * Draw selection, unless it's regular and we don't want to
@@ -1451,7 +1457,7 @@ selscroll(int orig, int n) {
1451 sel.oe.x = term.col; 1457 sel.oe.x = term.col;
1452 } 1458 }
1453 } 1459 }
1454 selsort(); 1460 selnormalize();
1455 } 1461 }
1456} 1462}
1457 1463