ref: 6632edc3102c6e436b9123f3515b86ff754626f6
parent: 7536ca46fb6f9ead715fef915371ceadf8562acb
author: phil9 <[email protected]>
date: Tue Jan 30 01:21:58 EST 2024
fix scrolling issues scrolling would stop working properly when keeping a button pressed and the mouse leaving the scrollbar.
--- a/vdiff.c
+++ b/vdiff.c
@@ -54,6 +54,8 @@
int lineh;
int nlines;
int offset;
+int scrolling;
+int oldbuttons;
Line **lines;
int lsize;
int lcount;
@@ -143,6 +145,15 @@
}
void
+clampoffset(void)
+{
+ if(offset<0)
+ offset = 0;
+ if(offset+nlines>lcount)
+ offset = lcount-nlines+1;
+}
+
+void
scroll(int off)
{
if(off<0 && offset<=0)
@@ -150,10 +161,7 @@
if(off>0 && offset+nlines>lcount)
return;
offset += off;
- if(offset<0)
- offset = 0;
- if(offset+nlines>lcount)
- offset = lcount-nlines+1;
+ clampoffset();
redraw();
}
@@ -229,7 +237,12 @@
{
int n;
- if(ptinrect(m.xy, scrollr)){
+ if(oldbuttons == 0 && m.buttons != 0 && ptinrect(m.xy, scrollr))
+ scrolling = 1;
+ else if(m.buttons == 0)
+ scrolling = 0;
+
+ if(scrolling){
if(m.buttons&1){
n = (m.xy.y - scrollr.min.y) / lineh;
if(-n<lcount-offset){
@@ -241,6 +254,7 @@
}else if(m.buttons&2){
n = (m.xy.y - scrollr.min.y) * lcount / Dy(scrollr);
offset = n;
+ clampoffset();
redraw();
}else if(m.buttons&4){
n = (m.xy.y - scrollr.min.y) / lineh;
@@ -251,15 +265,17 @@
}
return;
}
+ }else{
+ if(m.buttons&4){
+ n = indexat(m.xy);
+ if(n>=0 && lines[n+offset]->f != nil)
+ plumb(lines[n+offset]->f, lines[n+offset]->l);
+ }else if(m.buttons&8)
+ scroll(-scrollsize);
+ else if(m.buttons&16)
+ scroll(scrollsize);
}
- if(m.buttons&4){
- n = indexat(m.xy);
- if(n>=0 && lines[n+offset]->f != nil)
- plumb(lines[n+offset]->f, lines[n+offset]->l);
- }else if(m.buttons&8)
- scroll(-scrollsize);
- else if(m.buttons&16)
- scroll(scrollsize);
+ oldbuttons = m.buttons;
}
void
@@ -417,6 +433,8 @@
};
int b;
+ scrolling = 0;
+ oldbuttons = 0;
b = 0;
ARGBEGIN{
case 'b':