diff options
| author | Christoph Lohmann <20h@r-36.net> | 2013-04-21 13:01:16 +0200 |
|---|---|---|
| committer | Christoph Lohmann <20h@r-36.net> | 2013-04-21 13:01:16 +0200 |
| commit | b596d6ba3c50bc379adc298a4e2ba7c122b116ab (patch) | |
| tree | d7091bd2c3d8ec72bf978019096026b5348e6ea1 | |
| parent | 872a7f18eaffd96eefb31e3dcb45fd86bc67029b (diff) | |
| download | st-b596d6ba3c50bc379adc298a4e2ba7c122b116ab.tar.gz st-b596d6ba3c50bc379adc298a4e2ba7c122b116ab.zip | |
Adding wrap handling in selection.
| -rw-r--r-- | st.c | 37 |
1 files changed, 23 insertions, 14 deletions
| @@ -85,6 +85,7 @@ enum glyph_attribute { | |||
| 85 | ATTR_GFX = 8, | 85 | ATTR_GFX = 8, |
| 86 | ATTR_ITALIC = 16, | 86 | ATTR_ITALIC = 16, |
| 87 | ATTR_BLINK = 32, | 87 | ATTR_BLINK = 32, |
| 88 | ATTR_WRAP = 64, | ||
| 88 | }; | 89 | }; |
| 89 | 90 | ||
| 90 | enum cursor_movement { | 91 | enum cursor_movement { |
| @@ -668,17 +669,15 @@ void | |||
| 668 | selsnap(int mode, int *x, int *y, int direction) { | 669 | selsnap(int mode, int *x, int *y, int direction) { |
| 669 | switch(mode) { | 670 | switch(mode) { |
| 670 | case SNAP_WORD: | 671 | case SNAP_WORD: |
| 671 | while(*x > 0 && *x < term.col-1 && term.line[*y][*x + direction].c[0] != ' ') { | 672 | while(*x > 0 && *x < term.col-1 |
| 673 | && term.line[*y][*x + direction].c[0] != ' ') { | ||
| 672 | *x += direction; | 674 | *x += direction; |
| 673 | } | 675 | } |
| 674 | break; | 676 | break; |
| 675 | |||
| 676 | case SNAP_LINE: | 677 | case SNAP_LINE: |
| 677 | *x = (direction < 0) ? 0 : term.col - 1; | 678 | *x = (direction < 0) ? 0 : term.col - 1; |
| 678 | break; | 679 | break; |
| 679 | |||
| 680 | default: | 680 | default: |
| 681 | /* do nothing */ | ||
| 682 | break; | 681 | break; |
| 683 | } | 682 | } |
| 684 | } | 683 | } |
| @@ -771,6 +770,7 @@ bpress(XEvent *e) { | |||
| 771 | mousereport(e); | 770 | mousereport(e); |
| 772 | } else if(e->xbutton.button == Button1) { | 771 | } else if(e->xbutton.button == Button1) { |
| 773 | gettimeofday(&now, NULL); | 772 | gettimeofday(&now, NULL); |
| 773 | |||
| 774 | /* Clear previous selection, logically and visually. */ | 774 | /* Clear previous selection, logically and visually. */ |
| 775 | if(sel.bx != -1) { | 775 | if(sel.bx != -1) { |
| 776 | sel.bx = -1; | 776 | sel.bx = -1; |
| @@ -781,14 +781,15 @@ bpress(XEvent *e) { | |||
| 781 | sel.type = SEL_REGULAR; | 781 | sel.type = SEL_REGULAR; |
| 782 | sel.ex = sel.bx = x2col(e->xbutton.x); | 782 | sel.ex = sel.bx = x2col(e->xbutton.x); |
| 783 | sel.ey = sel.by = y2row(e->xbutton.y); | 783 | sel.ey = sel.by = y2row(e->xbutton.y); |
| 784 | |||
| 784 | /* | 785 | /* |
| 785 | * Snap handling. | 786 | * Snap handling. |
| 786 | * If user clicks are fasst enough (e.g. below timeouts), | 787 | * If user clicks are fasst enough (e.g. below timeouts), |
| 787 | * we ignore if his hand slipped left or down and accidentally selected more; | 788 | * we ignore if his hand slipped left or down and accidentally |
| 788 | * we are just snapping to whatever we're snapping. | 789 | * selected more; we are just snapping to whatever we're |
| 790 | * snapping. | ||
| 789 | */ | 791 | */ |
| 790 | if(TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) { | 792 | if(TIMEDIFF(now, sel.tclick2) <= tripleclicktimeout) { |
| 791 | /* Snap to line */ | ||
| 792 | sel.snap = SNAP_LINE; | 793 | sel.snap = SNAP_LINE; |
| 793 | } else if(TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) { | 794 | } else if(TIMEDIFF(now, sel.tclick1) <= doubleclicktimeout) { |
| 794 | sel.snap = SNAP_WORD; | 795 | sel.snap = SNAP_WORD; |
| @@ -797,8 +798,15 @@ bpress(XEvent *e) { | |||
| 797 | } | 798 | } |
| 798 | selsnap(sel.snap, &sel.bx, &sel.by, -1); | 799 | selsnap(sel.snap, &sel.bx, &sel.by, -1); |
| 799 | selsnap(sel.snap, &sel.ex, &sel.ey, 1); | 800 | selsnap(sel.snap, &sel.ex, &sel.ey, 1); |
| 800 | sel.b.x = sel.bx, sel.b.y = sel.by, sel.e.x = sel.ex, sel.e.y = sel.ey; | 801 | sel.b.x = sel.bx; |
| 801 | /* Draw selection, unless it's regular and we don't want to make clicks visible */ | 802 | sel.b.y = sel.by; |
| 803 | sel.e.x = sel.ex; | ||
| 804 | sel.e.y = sel.ey; | ||
| 805 | |||
| 806 | /* | ||
| 807 | * Draw selection, unless it's regular and we don't want to | ||
| 808 | * make clicks visible | ||
| 809 | */ | ||
| 802 | if (sel.snap != 0) { | 810 | if (sel.snap != 0) { |
| 803 | tsetdirt(sel.b.y, sel.e.y); | 811 | tsetdirt(sel.b.y, sel.e.y); |
| 804 | draw(); | 812 | draw(); |
| @@ -834,9 +842,8 @@ selcopy(void) { | |||
| 834 | /* nothing */; | 842 | /* nothing */; |
| 835 | 843 | ||
| 836 | for(x = 0; gp <= last; x++, ++gp) { | 844 | for(x = 0; gp <= last; x++, ++gp) { |
| 837 | if(!selected(x, y)) { | 845 | if(!selected(x, y)) |
| 838 | continue; | 846 | continue; |
| 839 | } | ||
| 840 | 847 | ||
| 841 | size = utf8size(gp->c); | 848 | size = utf8size(gp->c); |
| 842 | memcpy(ptr, gp->c, size); | 849 | memcpy(ptr, gp->c, size); |
| @@ -852,7 +859,7 @@ selcopy(void) { | |||
| 852 | * st. | 859 | * st. |
| 853 | * FIXME: Fix the computer world. | 860 | * FIXME: Fix the computer world. |
| 854 | */ | 861 | */ |
| 855 | if(y < sel.e.y) | 862 | if(y < sel.e.y && !((gp-1)->mode & ATTR_WRAP)) |
| 856 | *ptr++ = '\n'; | 863 | *ptr++ = '\n'; |
| 857 | } | 864 | } |
| 858 | *ptr = 0; | 865 | *ptr = 0; |
| @@ -2266,8 +2273,10 @@ tputc(char *c, int len) { | |||
| 2266 | return; | 2273 | return; |
| 2267 | if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey)) | 2274 | if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey)) |
| 2268 | sel.bx = -1; | 2275 | sel.bx = -1; |
| 2269 | if(IS_SET(MODE_WRAP) && term.c.state & CURSOR_WRAPNEXT) | 2276 | if(IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) { |
| 2270 | tnewline(1); /* always go to first col */ | 2277 | term.line[term.c.y][term.c.x].mode |= ATTR_WRAP; |
| 2278 | tnewline(1); | ||
| 2279 | } | ||
| 2271 | 2280 | ||
| 2272 | if(IS_SET(MODE_INSERT) && term.c.x+1 < term.col) { | 2281 | if(IS_SET(MODE_INSERT) && term.c.x+1 < term.col) { |
| 2273 | memmove(&term.line[term.c.y][term.c.x+1], | 2282 | memmove(&term.line[term.c.y][term.c.x+1], |
