Thumbnail

rani/cscroll.git

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

commit b6b9fdc67f12a789e9792589b9be15996849c3ad Author: Raniconduh <clagv.randomgames@gmail.com> Date: Tue Oct 18 11:12:31 2022 +0000 set cursor to old directory when chdir back diff --git a/include/io.h b/include/io.h index ab8f206..2a94694 100644 --- a/include/io.h +++ b/include/io.h @@ -706 +707 @@ void set_color(void);  void print_mode(struct dir_entry_t *);  void padstr(size_t);  void resize_fbuf(void); +void resize_fbufcur(long);  void print_oneshot(void);  enum colors get_file_color(struct dir_entry_t *);  char get_file_ident(struct dir_entry_t *); diff --git a/src/io.c b/src/io.c index 9d263f7..5f27f2c 100644 --- a/src/io.c +++ b/src/io.c @@ -4336 +43326 @@ void resize_fbuf(void) {  }     +void resize_fbufcur(long c) { + // 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; + } +} + +  int get_fwidth(struct dir_entry_t * de) {   int w = 0;   w += strlen(de->name); diff --git a/src/main.c b/src/main.c index e494fef..e931592 100644 --- a/src/main.c +++ b/src/main.c @@ -16313 +16330 @@ int main(int argc, char ** argv) {   break;   case KEY_LEFT:   case CTRL_B: - case 'h': + case 'h':; + // can't cd back when in / + if (cwd[0] == '/' && cwd[1] == '\0') break; + + char * cur_dir = strdup(strrchr(cwd, '/') + 1); +   cd_back();   free_dir_entries();   list_dir(cwd); +   cursor = 1; - first_f = 0; - last_f = LAST_F; + + // set cursor to old dir + long lc = search_file(cursor, cur_dir); + if (lc >= 0) { + cursor = lc + 1; + resize_fbufcur(lc); + } else { + cursor = 1; + first_f = 0; + last_f = LAST_F; + } + + free(cur_dir);   break;   case KEY_RIGHT:   case CTRL_F: @@ -36926 +3869 @@ int main(int argc, char ** argv) {   free(search_str);     if (c == -1) break; -   cursor = c + 1;   - // 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; - } - + resize_fbufcur(c);   break;   case '!':;   char * cmd = curses_getline("!");