diff options
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 46 |
1 files changed, 26 insertions, 20 deletions
| @@ -441,7 +441,7 @@ static void selclear(XEvent *); | |||
| 441 | static void selrequest(XEvent *); | 441 | static void selrequest(XEvent *); |
| 442 | 442 | ||
| 443 | static void selinit(void); | 443 | static void selinit(void); |
| 444 | static void selsort(void); | 444 | static void selnormalize(void); |
| 445 | static inline bool selected(int, int); | 445 | static inline bool selected(int, int); |
| 446 | static char *getsel(void); | 446 | static char *getsel(void); |
| 447 | static void selcopy(void); | 447 | static 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 | ||
| 660 | static 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 | |||
| 660 | static void | 669 | static void |
| 661 | selsort(void) { | 670 | selnormalize(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 | ||
| 673 | static inline bool | 693 | static inline bool |
| @@ -683,8 +703,6 @@ selected(int x, int y) { | |||
| 683 | 703 | ||
| 684 | void | 704 | void |
| 685 | selsnap(int mode, int *x, int *y, int direction) { | 705 | selsnap(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 | ||
