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>
This commit is contained in:
parent
6fd887077e
commit
5159d55c63
46
st.c
46
st.c
|
@ -703,6 +703,9 @@ selected(int x, int y) {
|
||||||
|
|
||||||
void
|
void
|
||||||
selsnap(int mode, int *x, int *y, int direction) {
|
selsnap(int mode, int *x, int *y, int direction) {
|
||||||
|
int newx, newy, xt, yt;
|
||||||
|
Glyph *gp;
|
||||||
|
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case SNAP_WORD:
|
case SNAP_WORD:
|
||||||
/*
|
/*
|
||||||
|
@ -710,36 +713,31 @@ selsnap(int mode, int *x, int *y, int direction) {
|
||||||
* beginning of a line.
|
* beginning of a line.
|
||||||
*/
|
*/
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(direction < 0 && *x <= 0) {
|
newx = *x + direction;
|
||||||
if(*y > 0 && term.line[*y - 1][term.col-1].mode
|
newy = *y;
|
||||||
& ATTR_WRAP) {
|
if(!BETWEEN(newx, 0, term.col - 1)) {
|
||||||
*y -= 1;
|
newy += direction;
|
||||||
*x = term.col-1;
|
newx = (newx + term.col) % term.col;
|
||||||
} else {
|
if (!BETWEEN(newy, 0, term.row - 1))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
if(direction > 0)
|
||||||
if(direction > 0 && *x >= term.col-1) {
|
yt = *y, xt = *x;
|
||||||
if(*y < term.row-1 && term.line[*y][*x].mode
|
else
|
||||||
& ATTR_WRAP) {
|
yt = newy, xt = newx;
|
||||||
*y += 1;
|
if(!(term.line[yt][xt].mode & ATTR_WRAP))
|
||||||
*x = 0;
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(term.line[*y][*x+direction].mode & ATTR_WDUMMY) {
|
if (newx >= tlinelen(newy))
|
||||||
*x += direction;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(*x >= tlinelen(*y) || strchr(worddelimiters,
|
|
||||||
term.line[*y][*x+direction].c[0])) {
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
*x += direction;
|
gp = &term.line[newy][newx];
|
||||||
|
if (!(gp->mode & ATTR_WDUMMY) && strchr(worddelimiters, gp->c[0]))
|
||||||
|
break;
|
||||||
|
|
||||||
|
*x = newx;
|
||||||
|
*y = newy;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SNAP_LINE:
|
case SNAP_LINE:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user