Thumbnail

rani/cscroll.git

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

commit 57f5f125337cb1021e510fab7df992dbf03d38d2 Author: rani <clagv.randomgames@gmail.com> Date: Fri Aug 26 18:28:28 2022 +0000 open file/dir when clicking on highlighted file diff --git a/include/commands.h b/include/commands.h index 9002050..a10893f 100644 --- a/include/commands.h +++ b/include/commands.h @@ -96 +97 @@ void paste_cuts(char *);  void run_cmd(char *);  void set(char *);  void unset(char *); +void open_cur_file(void);    extern bool cutting;  extern char * cut_start_dir; diff --git a/src/commands.c b/src/commands.c index fc54b97..89dbd99 100644 --- a/src/commands.c +++ b/src/commands.c @@ -106 +107 @@  #include "dir.h"  #include "var.h"  #include "opts.h" +#include "main.h"  #include "commands.h"     @@ -1613 +16220 @@ void unset(char * v) {   napms(500);   }  } + + +// attempt to "open" the file the cursor is on +void open_cur_file(void) { + // enter directtory/link pointing to dir + if (dir_entries[cursor - 1]->file_type == FILE_DIR || + dir_entries[cursor - 1]->under_link == FILE_DIR) { + enter_dir(dir_entries[cursor - 1]->name); + free_dir_entries(); + list_dir(cwd); + cursor = 1; + first_f = 0; + last_f = LAST_F; + } else { + ext_open(dir_entries[cursor - 1]->name); + } +} diff --git a/src/main.c b/src/main.c index 8cd89c4..e4fa4b2 100644 --- a/src/main.c +++ b/src/main.c @@ -12927 +12927 @@ int main(int argc, char ** argv) {   case 'l':   case '\n':   if (!n_dir_entries) break; - // open directory or links that point to a directory - if (dir_entries[cursor - 1]->file_type == FILE_DIR || - dir_entries[cursor - 1]->under_link == FILE_DIR) { - enter_dir(dir_entries[cursor - 1]->name); - free_dir_entries(); - list_dir(cwd); - cursor = 1; - first_f = 0; - last_f = LAST_F; - } else { - ext_open(dir_entries[cursor - 1]->name); - } + open_cur_file();   break;   case KEY_MOUSE:;   MEVENT mouse_event; + bool ok = false; + unsigned norm_row = 0; // normalized row   if (getmouse(&mouse_event) == OK) { + ok = true;   int mrow = mouse_event.y; // row @ mouse click; start @ 1   if (mrow < 3 || mrow > LINES - 4) break; // 3 pad top/bottom   if ((unsigned)mrow - 3 >= n_dir_entries) break;   - cursor = first_f + mrow - 2; // 3-pad, mrow>0 + norm_row = first_f + mrow - 2; // 3-pad, mrow>0 + } + + if (ok) { + if (norm_row == cursor) { + open_cur_file(); + } else { + cursor = norm_row; + }   }     break;