ref: 692a7dd95ec710318bc5400e97b3ebbf85e89a3e
parent: cf29ee19bf527ca8bf82da1985ef96566a3343c6
author: phil9 <telephil9@gmail.com>
date: Sun Aug 15 00:50:40 EDT 2021
fix scrolling going out of bounds scrolling offset was going out of bounds when the number of visible lines was greater than the number of files to display. This lead to a bunch of unnamed files to appear. We now check whether scrolling is possible and also do not redraw when clicking the scrollbar but no scrolling will happen (ie offset does not change).
--- a/vdir.c
+++ b/vdir.c
@@ -315,9 +315,11 @@
int
scrollclamp(int offset)
{
- if(offset < 0)
+ if(nlines >= ndirs)
offset = 0;
- if(offset+nlines > ndirs)
+ else if(offset < 0)
+ offset = 0;
+ else if(offset+nlines > ndirs)
offset = ndirs-nlines;
return offset;
}
@@ -325,7 +327,12 @@
void
scrollup(int off)
{
- offset = scrollclamp(offset - off);
+ int newoff;
+
+ newoff = scrollclamp(offset - off);
+ if(newoff == offset)
+ return;
+ offset = newoff;
redraw();
}
@@ -332,7 +339,12 @@
void
scrolldown(int off)
{
- offset = scrollclamp(offset + off);
+ int newoff;
+
+ newoff = scrollclamp(offset + off);
+ if(newoff == offset)
+ return;
+ offset = newoff;
redraw();
}