Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit 54af8135074e0cf5398219255a9a586c0e40eff1 Author: Raniconduh <clagv.randomgames@gmail.com> Date: Sat Jun 18 13:32:33 2022 +0000 fixed overscroll in search function diff --git a/src/main.c b/src/main.c index d2e2f68..8868f89 100644 --- a/src/main.c +++ b/src/main.c @@ -3138 +31324 @@ int main(int argc, char ** argv) {   if (c == -1) break;     cursor = c + 1; - last_f = n_dir_entries - cursor > (unsigned)LINES - 6 ? cursor + LINES - 6 : n_dir_entries; - first_f = cursor > (unsigned)LINES - 6 ? last_f - LINES + 6 : 0; + + // all files can fit on screen + if (n_dir_entries <= (unsigned)LINES - 6) { + first_f = 0; + last_f = n_dir_entries; + // somewhere in middle but no need to scroll + } else if (cursor > first_f && cursor <= last_f) { + ; // no-op + // somewhere in the middle + } else if (cursor + LINES - 7 <= n_dir_entries) { + first_f = c; + last_f = first_f + LINES - 6; + // at the end + } else if (n_dir_entries > (unsigned)LINES - 6) { + last_f = n_dir_entries; + first_f = last_f - LINES + 6; + } +   break;   case '!':;   char * cmd = curses_getline("!");