shithub: riscv

Download patch

ref: 039015ad71aaacb6144c9b352f764432646d8b1e
parent: 92d5d58784130a456dec269ce0d876ba7ad89932
author: rodri <rgl@antares-labs.eu>
date: Thu May 9 07:49:09 EDT 2024

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.

--- a/sys/src/cmd/vdiff.c
+++ b/sys/src/cmd/vdiff.c
@@ -190,9 +190,9 @@
 	if(viewh < totalh){
 		h = ((double)viewh/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)
-			ye = scrollr.max.y - 1;
+			ye = scrollr.max.y;
 		scrposr = Rect(scrollr.min.x, scrollr.min.y+y+1, scrollr.max.x-1, ye);
 	}else
 		scrposr = Rect(scrollr.min.x, scrollr.min.y, scrollr.max.x-1, scrollr.max.y);
@@ -217,7 +217,7 @@
 {
 	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;
 	if(Δpan < 0 || max <= 0)
 		Δpan = 0;
@@ -360,7 +360,7 @@
 	else if(m.buttons == 0)
 		scrolling = 0;
 
-	n = (m.xy.y - scrollr.min.y);
+	n = (m.xy.y - viewr.min.y - Margin)/lineh * lineh;
 	if(scrolling){
 		if(m.buttons&1){
 			scroll(-n);
@@ -367,6 +367,7 @@
 			return;
 		}else if(m.buttons&2){
 			offset = (m.xy.y - scrollr.min.y) * totalh/Dy(scrollr);
+			offset = offset/lineh * lineh;
 			clampoffset();
 			redraw();
 		}else if(m.buttons&4){
@@ -377,7 +378,7 @@
 		scroll(-n);
 	}else if(m.buttons&16){
 		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++){
 			b = blocks[i];
 			if(ptinrect(addpt(m.xy, Pt(0, offset)), b->sr)){
@@ -598,8 +599,6 @@
 	};
 	int b;
 
-	scrolling = 0;
-	oldbuttons = 0;
 	b = 0;
 	ARGBEGIN{
 	case 'b':
@@ -620,7 +619,6 @@
 	}
 	if(initdraw(nil, nil, "vdiff")<0)
 		sysfatal("initdraw: %r");
-	display->locking = 0;
 	if((mctl = initmouse(nil, screen)) == nil)
 		sysfatal("initmouse: %r");
 	if((kctl = initkeyboard(nil)) == nil)