vdiff: fix scrolling and mouse button handling.

vertical scrolling now works in a line-wise manner,
just like in rio(1), sam(1) and friends. horizontal
scrolling showed problems with some line widths
where they got cut before showing the last
characters.

finally, pressing LMB or RMB and swiping while going
through any of the blocks caused a storm of plumbs
and visibility toggling (when over the expander line).
this doesn't happen anymore.
This commit is contained in:
rodri 2024-05-09 11:49:09 +00:00
parent 92d5d58784
commit 039015ad71

View file

@ -190,9 +190,9 @@ redraw(void)
if(viewh < totalh){ if(viewh < totalh){
h = ((double)viewh/totalh)*Dy(scrollr); h = ((double)viewh/totalh)*Dy(scrollr);
y = ((double)offset/totalh)*Dy(scrollr); y = ((double)offset/totalh)*Dy(scrollr);
ye = scrollr.min.y + y + h - 1; ye = scrollr.min.y + y + h;
if(ye >= scrollr.max.y) if(ye >= scrollr.max.y)
ye = scrollr.max.y - 1; ye = scrollr.max.y;
scrposr = Rect(scrollr.min.x, scrollr.min.y+y+1, scrollr.max.x-1, ye); scrposr = Rect(scrollr.min.x, scrollr.min.y+y+1, scrollr.max.x-1, ye);
}else }else
scrposr = Rect(scrollr.min.x, scrollr.min.y, scrollr.max.x-1, scrollr.max.y); scrposr = Rect(scrollr.min.x, scrollr.min.y, scrollr.max.x-1, scrollr.max.y);
@ -217,7 +217,7 @@ pan(int off)
{ {
int max; int max;
max = Hpadding + Margin + Hpadding + maxlength * spacew + 2 * ellipsisw - Dx(blocks[0]->r); max = Dx(scrollr) + Margin + Hpadding + maxlength*spacew + 2*ellipsisw + Hpadding + Margin - Dx(blocks[0]->r)/2;
Δpan += off * spacew; Δpan += off * spacew;
if(Δpan < 0 || max <= 0) if(Δpan < 0 || max <= 0)
Δpan = 0; Δpan = 0;
@ -360,13 +360,14 @@ emouse(Mouse m)
else if(m.buttons == 0) else if(m.buttons == 0)
scrolling = 0; scrolling = 0;
n = (m.xy.y - scrollr.min.y); n = (m.xy.y - viewr.min.y - Margin)/lineh * lineh;
if(scrolling){ if(scrolling){
if(m.buttons&1){ if(m.buttons&1){
scroll(-n); scroll(-n);
return; return;
}else if(m.buttons&2){ }else if(m.buttons&2){
offset = (m.xy.y - scrollr.min.y) * totalh/Dy(scrollr); offset = (m.xy.y - scrollr.min.y) * totalh/Dy(scrollr);
offset = offset/lineh * lineh;
clampoffset(); clampoffset();
redraw(); redraw();
}else if(m.buttons&4){ }else if(m.buttons&4){
@ -377,7 +378,7 @@ emouse(Mouse m)
scroll(-n); scroll(-n);
}else if(m.buttons&16){ }else if(m.buttons&16){
scroll(n); scroll(n);
}else if(m.buttons != 0 && ptinrect(m.xy, viewr)){ }else if((oldbuttons^m.buttons) != 0 && ptinrect(m.xy, viewr)){
for(i = 0; i < nblocks; i++){ for(i = 0; i < nblocks; i++){
b = blocks[i]; b = blocks[i];
if(ptinrect(addpt(m.xy, Pt(0, offset)), b->sr)){ if(ptinrect(addpt(m.xy, Pt(0, offset)), b->sr)){
@ -598,8 +599,6 @@ threadmain(int argc, char *argv[])
}; };
int b; int b;
scrolling = 0;
oldbuttons = 0;
b = 0; b = 0;
ARGBEGIN{ ARGBEGIN{
case 'b': case 'b':
@ -620,7 +619,6 @@ threadmain(int argc, char *argv[])
} }
if(initdraw(nil, nil, "vdiff")<0) if(initdraw(nil, nil, "vdiff")<0)
sysfatal("initdraw: %r"); sysfatal("initdraw: %r");
display->locking = 0;
if((mctl = initmouse(nil, screen)) == nil) if((mctl = initmouse(nil, screen)) == nil)
sysfatal("initmouse: %r"); sysfatal("initmouse: %r");
if((kctl = initkeyboard(nil)) == nil) if((kctl = initkeyboard(nil)) == nil)