From 4b4277b306b11ff66f7c24d376b7ec26a1f74f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Fri, 22 Jun 2018 17:10:36 +0200 Subject: [PATCH] Make sure to fill the view when possible When there were more items than would fit on the screen and the cursor was at the end of the list, a reload causing items to disappear or a vertical terminal enlargement would fail to adjust the start offset. --- sdn.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdn.cpp b/sdn.cpp index 3482de0..75624ad 100644 --- a/sdn.cpp +++ b/sdn.cpp @@ -491,7 +491,6 @@ fun reload () { g.cursor = min (g.cursor, int (g.entries.size ()) - 1); g.offset = min (g.offset, int (g.entries.size ()) - 1); - update (); if (g.inotify_wd != -1) inotify_rm_watch (g.inotify_fd, g.inotify_wd); @@ -648,6 +647,10 @@ fun handle (wint_t c, bool is_char) -> bool { g.cursor = max (g.cursor, 0); g.cursor = min (g.cursor, int (g.entries.size ()) - 1); + // Decrease the offset when more items can suddenly fit + int pushable = visible_lines () - (int (g.entries.size ()) - g.offset); + g.offset -= max (pushable, 0); + // Make sure cursor is visible g.offset = max (g.offset, 0); g.offset = min (g.offset, int (g.entries.size ()) - 1); @@ -791,6 +794,7 @@ int main (int argc, char *argv[]) { load_configuration (); reload (); + update (); auto start_dir = g.cwd; wint_t c;