]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/libframe/frinsert.c
qer(8): correct man page example (thanks, kenji)
[plan9front.git] / sys / src / libframe / frinsert.c
index 2c40955bad506db7c49f3b5f9a8e8ad869cdbea0..377c55413f7868bda24436600680e46f6725243f 100644 (file)
@@ -78,11 +78,10 @@ static
 void
 chopframe(Frame *f, Point pt, ulong p, int bn)
 {
-       Frbox *b;
+       Frbox *b, *eb;
 
-       for(b = &f->box[bn]; ; b++){
-               if(b >= &f->box[f->nbox])
-                       drawerror(f->display, "endofframe");
+       eb = &f->box[f->nbox];
+       for(b = &f->box[bn]; b < eb; b++){
                _frcklinewrap(f, &pt, b);
                if(pt.y >= f->r.max.y)
                        break;
@@ -91,7 +90,7 @@ chopframe(Frame *f, Point pt, ulong p, int bn)
        }
        f->nchars = p;
        f->nlines = f->maxlines;
-       if(b<&f->box[f->nbox])                          /* BUG */
+       if(b < eb)                              /* BUG */
                _frdelbox(f, (int)(b-f->box), f->nbox-1);
 }
 
@@ -102,7 +101,7 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
        Frbox *b;
        int n, n0, nn0, y;
        ulong cn0;
-       Image *col;
+       Image *back, *text;
        Rectangle r;
        static struct{
                Point pt0, pt1;
@@ -220,10 +219,10 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
                                r.max.x = f->r.max.x;
                                r.max.y += f->font->height;
                                if(f->p0<=cn0 && cn0<f->p1)     /* b+1 is inside selection */
-                                       col = f->cols[HIGH];
+                                       back = f->cols[HIGH];
                                else
-                                       col = f->cols[BACK];
-                               draw(f->b, r, col, nil, r.min);
+                                       back = f->cols[BACK];
+                               draw(f->b, r, back, nil, r.min);
                        }else if(pt.y < y){
                                r.min = pt;
                                r.max = pt;
@@ -231,10 +230,10 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
                                r.max.x = f->r.max.x;
                                r.max.y += f->font->height;
                                if(f->p0<=cn0 && cn0<f->p1)     /* b+1 is inside selection */
-                                       col = f->cols[HIGH];
+                                       back = f->cols[HIGH];
                                else
-                                       col = f->cols[BACK];
-                               draw(f->b, r, col, nil, r.min);
+                                       back = f->cols[BACK];
+                               draw(f->b, r, back, nil, r.min);
                        }
                        y = pt.y;
                        cn0 -= b->nrune;
@@ -247,22 +246,26 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
                                r.max.x = f->r.max.x;
                        cn0--;
                        if(f->p0<=cn0 && cn0<f->p1)     /* b is inside selection */
-                               col = f->cols[HIGH];
+                               back = f->cols[HIGH];
                        else
-                               col = f->cols[BACK];
-                       draw(f->b, r, col, nil, r.min);
+                               back = f->cols[BACK];
+                       draw(f->b, r, back, nil, r.min);
                        y = 0;
                        if(pt.x == f->r.min.x)
                                y = pt.y;
                }
        }
        /* insertion can extend the selection, so the condition here is different */
-       if(f->p0<p0 && p0<=f->p1)
-               col = f->cols[HIGH];
-       else
-               col = f->cols[BACK];
-       frselectpaint(f, ppt0, ppt1, col);
-       _frdrawtext(&frame, ppt0, f->cols[TEXT], col);
+       if(f->p0<p0 && p0<=f->p1){
+               text = f->cols[HTEXT];
+               back = f->cols[HIGH];
+       }
+       else {
+               text = f->cols[TEXT];
+               back = f->cols[BACK];
+       }
+       frselectpaint(f, ppt0, ppt1, back);
+       _frdrawtext(&frame, ppt0, text, back);
        _fraddbox(f, nn0, frame.nbox);
        for(n=0; n<frame.nbox; n++)
                f->box[nn0+n] = frame.box[n];