JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Remove indentation level in xdrawcursor
[st.git] / st.c
diff --git a/st.c b/st.c
index 6165119..dd3301b 100644 (file)
--- a/st.c
+++ b/st.c
@@ -662,7 +662,10 @@ y2row(int y) {
 static int tlinelen(int y) {
        int i = term.col;
 
-       while (i > 0 && term.line[y][i - 1].c[0] == ' ')
+       if(term.line[y][i - 1].mode & ATTR_WRAP)
+               return i;
+
+       while(i > 0 && term.line[y][i - 1].c[0] == ' ')
                --i;
 
        return i;
@@ -682,6 +685,9 @@ selnormalize(void) {
        sel.nb.y = MIN(sel.ob.y, sel.oe.y);
        sel.ne.y = MAX(sel.ob.y, sel.oe.y);
 
+       selsnap(sel.snap, &sel.nb.x, &sel.nb.y, -1);
+       selsnap(sel.snap, &sel.ne.x, &sel.ne.y, +1);
+
        /* expand selection over line breaks */
        if (sel.type == SEL_RECTANGULAR)
                return;
@@ -706,7 +712,8 @@ selected(int x, int y) {
 void
 selsnap(int mode, int *x, int *y, int direction) {
        int newx, newy, xt, yt;
-       Glyph *gp;
+       bool delim, prevdelim;
+       Glyph *gp, *prevgp;
 
        switch(mode) {
        case SNAP_WORD:
@@ -714,6 +721,8 @@ selsnap(int mode, int *x, int *y, int direction) {
                 * Snap around if the word wraps around at the end or
                 * beginning of a line.
                 */
+               prevgp = &term.line[*y][*x];
+               prevdelim = strchr(worddelimiters, prevgp->c[0]) != NULL;
                for(;;) {
                        newx = *x + direction;
                        newy = *y;
@@ -735,11 +744,15 @@ selsnap(int mode, int *x, int *y, int direction) {
                                break;
 
                        gp = &term.line[newy][newx];
-                       if (!(gp->mode & ATTR_WDUMMY) && strchr(worddelimiters, gp->c[0]))
+                       delim = strchr(worddelimiters, gp->c[0]) != NULL;
+                       if(!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
+                                       || (delim && gp->c[0] != prevgp->c[0])))
                                break;
 
                        *x = newx;
                        *y = newy;
+                       prevgp = gp;
+                       prevdelim = delim;
                }
                break;
        case SNAP_LINE:
@@ -777,15 +790,6 @@ getbuttoninfo(XEvent *e) {
 
        sel.oe.x = x2col(e->xbutton.x);
        sel.oe.y = y2row(e->xbutton.y);
-
-       if(sel.ob.y < sel.oe.y
-                       || (sel.ob.y == sel.oe.y && sel.ob.x < sel.oe.x)) {
-               selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
-               selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
-       } else {
-               selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1);
-               selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1);
-       }
        selnormalize();
 
        sel.type = SEL_REGULAR;
@@ -900,8 +904,6 @@ bpress(XEvent *e) {
                } else {
                        sel.snap = 0;
                }
-               selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
-               selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
                selnormalize();
 
                /*
@@ -960,7 +962,7 @@ getsel(void) {
                 * st.
                 * FIXME: Fix the computer world.
                 */
-               if(sel.ne.y > y || lastx >= linelen)
+               if((y < sel.ne.y || lastx >= linelen) && !(last->mode & ATTR_WRAP))
                        *ptr++ = '\n';
        }
        *ptr = 0;
@@ -3457,39 +3459,40 @@ xdrawcursor(void) {
        xdraws(term.line[oldy][oldx].c, term.line[oldy][oldx], oldx,
                        oldy, width, sl);
 
+       if(IS_SET(MODE_HIDE))
+               return;
+
        /* draw the new one */
-       if(!(IS_SET(MODE_HIDE))) {
-               if(xw.state & WIN_FOCUSED) {
-                       if(IS_SET(MODE_REVERSE)) {
-                               g.mode |= ATTR_REVERSE;
-                               g.fg = defaultcs;
-                               g.bg = defaultfg;
-                       }
+       if(xw.state & WIN_FOCUSED) {
+               if(IS_SET(MODE_REVERSE)) {
+                       g.mode |= ATTR_REVERSE;
+                       g.fg = defaultcs;
+                       g.bg = defaultfg;
+               }
 
-                       sl = utf8len(g.c);
-                       width = (term.line[term.c.y][curx].mode & ATTR_WIDE)\
-                               ? 2 : 1;
-                       xdraws(g.c, g, term.c.x, term.c.y, width, sl);
-               } else {
-                       XftDrawRect(xw.draw, &dc.col[defaultcs],
-                                       borderpx + curx * xw.cw,
-                                       borderpx + term.c.y * xw.ch,
-                                       xw.cw - 1, 1);
-                       XftDrawRect(xw.draw, &dc.col[defaultcs],
-                                       borderpx + curx * xw.cw,
-                                       borderpx + term.c.y * xw.ch,
-                                       1, xw.ch - 1);
-                       XftDrawRect(xw.draw, &dc.col[defaultcs],
-                                       borderpx + (curx + 1) * xw.cw - 1,
-                                       borderpx + term.c.y * xw.ch,
-                                       1, xw.ch - 1);
-                       XftDrawRect(xw.draw, &dc.col[defaultcs],
-                                       borderpx + curx * xw.cw,
-                                       borderpx + (term.c.y + 1) * xw.ch - 1,
-                                       xw.cw, 1);
-               }
-               oldx = curx, oldy = term.c.y;
-       }
+               sl = utf8len(g.c);
+               width = (term.line[term.c.y][curx].mode & ATTR_WIDE)\
+                       ? 2 : 1;
+               xdraws(g.c, g, term.c.x, term.c.y, width, sl);
+       } else {
+               XftDrawRect(xw.draw, &dc.col[defaultcs],
+                               borderpx + curx * xw.cw,
+                               borderpx + term.c.y * xw.ch,
+                               xw.cw - 1, 1);
+               XftDrawRect(xw.draw, &dc.col[defaultcs],
+                               borderpx + curx * xw.cw,
+                               borderpx + term.c.y * xw.ch,
+                               1, xw.ch - 1);
+               XftDrawRect(xw.draw, &dc.col[defaultcs],
+                               borderpx + (curx + 1) * xw.cw - 1,
+                               borderpx + term.c.y * xw.ch,
+                               1, xw.ch - 1);
+               XftDrawRect(xw.draw, &dc.col[defaultcs],
+                               borderpx + curx * xw.cw,
+                               borderpx + (term.c.y + 1) * xw.ch - 1,
+                               xw.cw, 1);
+       }
+       oldx = curx, oldy = term.c.y;
 }