Xinqi Bao's Git
projects
/
st.git
/ blobdiff
summary
|
log
|
commit
|
diff
|
tree
raw
|
inline
| side by side
Refactor selsnap SNAP_WORD.
[st.git]
/
st.c
diff --git
a/st.c
b/st.c
index
9a41c5b
..
13226d8
100644
(file)
--- a/
st.c
+++ b/
st.c
@@
-670,7
+670,7
@@
static void
selnormalize(void) {
int i;
selnormalize(void) {
int i;
- if(sel.ob.y == sel.oe.y) {
+ if(sel.ob.y == sel.oe.y
|| sel.type == SEL_RECTANGULAR
) {
sel.nb.x = MIN(sel.ob.x, sel.oe.x);
sel.ne.x = MAX(sel.ob.x, sel.oe.x);
} else {
sel.nb.x = MIN(sel.ob.x, sel.oe.x);
sel.ne.x = MAX(sel.ob.x, sel.oe.x);
} else {
@@
-703,6
+703,9
@@
selected(int x, int y) {
void
selsnap(int mode, int *x, int *y, int direction) {
void
selsnap(int mode, int *x, int *y, int direction) {
+ int newx, newy, xt, yt;
+ Glyph *gp;
+
switch(mode) {
case SNAP_WORD:
/*
switch(mode) {
case SNAP_WORD:
/*
@@
-710,36
+713,31
@@
selsnap(int mode, int *x, int *y, int direction) {
* beginning of a line.
*/
for(;;) {
* beginning of a line.
*/
for(;;) {
- if(direction < 0 && *x <= 0) {
- if(*y > 0 && term.line[*y - 1][term.col-1].mode
-
& ATTR_WRAP
) {
-
*y -= 1
;
-
*x = term.col-1
;
- } else {
+ newx = *x + direction;
+ newy = *y;
+
if(!BETWEEN(newx, 0, term.col - 1)
) {
+
newy += direction
;
+
newx = (newx + term.col) % term.col
;
+ if (!BETWEEN(newy, 0, term.row - 1))
break;
break;
- }
- }
- if(direction > 0 && *x >= term.col-1) {
- if(*y < term.row-1 && term.line[*y][*x].mode
- & ATTR_WRAP) {
- *y += 1;
- *x = 0;
- } else {
+
+ if(direction > 0)
+ yt = *y, xt = *x;
+ else
+ yt = newy, xt = newx;
+ if(!(term.line[yt][xt].mode & ATTR_WRAP))
break;
break;
- }
}
}
- if(term.line[*y][*x+direction].mode & ATTR_WDUMMY) {
- *x += direction;
- continue;
- }
+ if (newx >= tlinelen(newy))
+ break;
- if(*x >= tlinelen(*y) || strchr(worddelimiters,
- term.line[*y][*x+direction].c[0])) {
+ gp = &term.line[newy][newx];
+ if (!(gp->mode & ATTR_WDUMMY) && strchr(worddelimiters, gp->c[0]))
break;
break;
- }
- *x += direction;
+ *x = newx;
+ *y = newy;
}
break;
case SNAP_LINE:
}
break;
case SNAP_LINE:
@@
-920,7
+918,7
@@
bpress(XEvent *e) {
char *
getsel(void) {
char *str, *ptr;
char *
getsel(void) {
char *str, *ptr;
- int x, y, bufsize, size,
i,
ex;
+ int x, y, bufsize, size, ex;
Glyph *gp, *last;
if(sel.ob.x == -1)
Glyph *gp, *last;
if(sel.ob.x == -1)
@@
-965,13
+963,10
@@
getsel(void) {
* after the visible text '\n' is appended.
*/
if(y == sel.ne.y) {
* after the visible text '\n' is appended.
*/
if(y == sel.ne.y) {
- i = term.col;
- while(--i > 0 && term.line[y][i].c[0] == ' ')
- /* nothing */;
ex = sel.ne.x;
if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
ex = sel.nb.x;
ex = sel.ne.x;
if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
ex = sel.nb.x;
- if(
i
< ex)
+ if(
tlinelen(y)
< ex)
*ptr++ = '\n';
}
}
*ptr++ = '\n';
}
}