diff options
| author | Colona <colona@ycc.fr> | 2014-06-05 06:32:01 +0200 |
|---|---|---|
| committer | Roberto E. Vargas Caballero <k0ga@shike2.com> | 2014-06-05 21:14:45 +0200 |
| commit | 5159d55c631cd1179bd2f872859d4540668745b9 (patch) | |
| tree | c4c051fe3a3f26452b01b786d0906357ed813fca | |
| parent | 6fd887077e29efd789499e06193314d7abdcac38 (diff) | |
| download | st-5159d55c631cd1179bd2f872859d4540668745b9.tar.gz st-5159d55c631cd1179bd2f872859d4540668745b9.zip | |
Refactor selsnap SNAP_WORD.
Refactor the SNAP_WORD part in selsnap, and fix a bug that caused the word
delimiters to be ignored if it was at the very beginning or end of a wrapped
line.
Signed-off-by: Roberto E. Vargas Caballero <k0ga@shike2.com>
| -rw-r--r-- | st.c | 44 |
1 files changed, 21 insertions, 23 deletions
| @@ -703,6 +703,9 @@ selected(int x, int y) { | |||
| 703 | 703 | ||
| 704 | void | 704 | void |
| 705 | selsnap(int mode, int *x, int *y, int direction) { | 705 | selsnap(int mode, int *x, int *y, int direction) { |
| 706 | int newx, newy, xt, yt; | ||
| 707 | Glyph *gp; | ||
| 708 | |||
| 706 | switch(mode) { | 709 | switch(mode) { |
| 707 | case SNAP_WORD: | 710 | case SNAP_WORD: |
| 708 | /* | 711 | /* |
| @@ -710,36 +713,31 @@ selsnap(int mode, int *x, int *y, int direction) { | |||
| 710 | * beginning of a line. | 713 | * beginning of a line. |
| 711 | */ | 714 | */ |
| 712 | for(;;) { | 715 | for(;;) { |
| 713 | if(direction < 0 && *x <= 0) { | 716 | newx = *x + direction; |
| 714 | if(*y > 0 && term.line[*y - 1][term.col-1].mode | 717 | newy = *y; |
| 715 | & ATTR_WRAP) { | 718 | if(!BETWEEN(newx, 0, term.col - 1)) { |
| 716 | *y -= 1; | 719 | newy += direction; |
| 717 | *x = term.col-1; | 720 | newx = (newx + term.col) % term.col; |
| 718 | } else { | 721 | if (!BETWEEN(newy, 0, term.row - 1)) |
| 719 | break; | 722 | break; |
| 720 | } | 723 | |
| 721 | } | 724 | if(direction > 0) |
| 722 | if(direction > 0 && *x >= term.col-1) { | 725 | yt = *y, xt = *x; |
| 723 | if(*y < term.row-1 && term.line[*y][*x].mode | 726 | else |
| 724 | & ATTR_WRAP) { | 727 | yt = newy, xt = newx; |
| 725 | *y += 1; | 728 | if(!(term.line[yt][xt].mode & ATTR_WRAP)) |
| 726 | *x = 0; | ||
| 727 | } else { | ||
| 728 | break; | 729 | break; |
| 729 | } | ||
| 730 | } | 730 | } |
| 731 | 731 | ||
| 732 | if(term.line[*y][*x+direction].mode & ATTR_WDUMMY) { | 732 | if (newx >= tlinelen(newy)) |
| 733 | *x += direction; | 733 | break; |
| 734 | continue; | ||
| 735 | } | ||
| 736 | 734 | ||
| 737 | if(*x >= tlinelen(*y) || strchr(worddelimiters, | 735 | gp = &term.line[newy][newx]; |
| 738 | term.line[*y][*x+direction].c[0])) { | 736 | if (!(gp->mode & ATTR_WDUMMY) && strchr(worddelimiters, gp->c[0])) |
| 739 | break; | 737 | break; |
| 740 | } | ||
| 741 | 738 | ||
| 742 | *x += direction; | 739 | *x = newx; |
| 740 | *y = newy; | ||
| 743 | } | 741 | } |
| 744 | break; | 742 | break; |
| 745 | case SNAP_LINE: | 743 | case SNAP_LINE: |
