aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-06-22 17:10:36 +0200
committerPřemysl Janouch <p@janouch.name>2018-06-22 19:51:05 +0200
commit4b4277b306b11ff66f7c24d376b7ec26a1f74f9e (patch)
tree6af8548a35ee287a91eb341e57987669905ca323
parent712334c0ee7bcc0675bf6f94598b3140a14cd85d (diff)
downloadsdn-4b4277b306b11ff66f7c24d376b7ec26a1f74f9e.tar.gz
sdn-4b4277b306b11ff66f7c24d376b7ec26a1f74f9e.tar.xz
sdn-4b4277b306b11ff66f7c24d376b7ec26a1f74f9e.zip
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.
-rw-r--r--sdn.cpp6
1 files changed, 5 insertions, 1 deletions
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;