ref: b7f238577616a8ca247ef68ee00924cc9d0caf02
parent: cdb993dffbd3050112b2fc3a93d7f51eead2ec74
author: phil9 <telephil9@gmail.com>
date: Fri Feb 4 13:24:50 EST 2022
ensure selected message is visible in index when opening pager the selected message could end up hidden by the pager if it was after the top 10 lines which is the default number of lines that remain visible when collapsing the index. We now scroll to make sure the selected message is in the visible range of the index.
--- a/index.c
+++ b/index.c
@@ -73,7 +73,19 @@
mbox = mb;
}
+void
+ensureselvisible(void)
+{
+ int n;
+ if(sel > offset && sel < offset + nlines)
+ return;
+ offset = nlines*(sel/nlines);
+ n = mbox->list->nelts;
+ if(offset + n%nlines >= n)
+ offset = n - n%nlines;
+}
+
Message*
messageat(int index)
{
@@ -189,6 +201,7 @@
listr.min.x += Scrollwidth + Scrollgap;
listr.max.x -= Padding;
nlines = Dy(viewr) / lineh;
+ ensureselvisible();
return viewr;
}
@@ -244,8 +257,6 @@
void
select(int newsel, Channel *c)
{
- int n;
-
if(newsel < 0)
newsel = 0;
if(newsel >= mbox->count)
@@ -254,10 +265,7 @@
return;
if(newsel < offset || newsel >= offset + nlines){
sel = newsel;
- offset = nlines*(sel/nlines);
- n = mbox->list->nelts;
- if(offset + n%nlines >= n)
- offset = n - n%nlines;
+ ensureselvisible();
indexdraw();
}else{
drawmessage(sel, 0);