libframe: use correct text color on frinsert depending on selection (thanks sl)

frinsert() used cols[TEXT] for drawing selected text instead of the
HTEXT color. this was discovered with rio -b.
This commit is contained in:
cinap_lenrek 2014-07-17 23:29:55 +02:00
parent e4436ec0bb
commit 4a7d29dd5f

View file

@ -101,7 +101,7 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
Frbox *b; Frbox *b;
int n, n0, nn0, y; int n, n0, nn0, y;
ulong cn0; ulong cn0;
Image *col; Image *back, *text;
Rectangle r; Rectangle r;
static struct{ static struct{
Point pt0, pt1; Point pt0, pt1;
@ -219,10 +219,10 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
r.max.x = f->r.max.x; r.max.x = f->r.max.x;
r.max.y += f->font->height; r.max.y += f->font->height;
if(f->p0<=cn0 && cn0<f->p1) /* b+1 is inside selection */ if(f->p0<=cn0 && cn0<f->p1) /* b+1 is inside selection */
col = f->cols[HIGH]; back = f->cols[HIGH];
else else
col = f->cols[BACK]; back = f->cols[BACK];
draw(f->b, r, col, nil, r.min); draw(f->b, r, back, nil, r.min);
}else if(pt.y < y){ }else if(pt.y < y){
r.min = pt; r.min = pt;
r.max = pt; r.max = pt;
@ -230,10 +230,10 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
r.max.x = f->r.max.x; r.max.x = f->r.max.x;
r.max.y += f->font->height; r.max.y += f->font->height;
if(f->p0<=cn0 && cn0<f->p1) /* b+1 is inside selection */ if(f->p0<=cn0 && cn0<f->p1) /* b+1 is inside selection */
col = f->cols[HIGH]; back = f->cols[HIGH];
else else
col = f->cols[BACK]; back = f->cols[BACK];
draw(f->b, r, col, nil, r.min); draw(f->b, r, back, nil, r.min);
} }
y = pt.y; y = pt.y;
cn0 -= b->nrune; cn0 -= b->nrune;
@ -246,22 +246,26 @@ frinsert(Frame *f, Rune *sp, Rune *ep, ulong p0)
r.max.x = f->r.max.x; r.max.x = f->r.max.x;
cn0--; cn0--;
if(f->p0<=cn0 && cn0<f->p1) /* b is inside selection */ if(f->p0<=cn0 && cn0<f->p1) /* b is inside selection */
col = f->cols[HIGH]; back = f->cols[HIGH];
else else
col = f->cols[BACK]; back = f->cols[BACK];
draw(f->b, r, col, nil, r.min); draw(f->b, r, back, nil, r.min);
y = 0; y = 0;
if(pt.x == f->r.min.x) if(pt.x == f->r.min.x)
y = pt.y; y = pt.y;
} }
} }
/* insertion can extend the selection, so the condition here is different */ /* insertion can extend the selection, so the condition here is different */
if(f->p0<p0 && p0<=f->p1) if(f->p0<p0 && p0<=f->p1){
col = f->cols[HIGH]; text = f->cols[HTEXT];
else back = f->cols[HIGH];
col = f->cols[BACK]; }
frselectpaint(f, ppt0, ppt1, col); else {
_frdrawtext(&frame, ppt0, f->cols[TEXT], col); text = f->cols[TEXT];
back = f->cols[BACK];
}
frselectpaint(f, ppt0, ppt1, back);
_frdrawtext(&frame, ppt0, text, back);
_fraddbox(f, nn0, frame.nbox); _fraddbox(f, nn0, frame.nbox);
for(n=0; n<frame.nbox; n++) for(n=0; n<frame.nbox; n++)
f->box[nn0+n] = frame.box[n]; f->box[nn0+n] = frame.box[n];