implementation of keeping the index of current file in between dir changes
This commit is contained in:
@@ -108,7 +108,7 @@ typedef struct Yank {
|
||||
} yank;
|
||||
typedef struct Linked_dir {
|
||||
char *path;
|
||||
unsigned long selected_file_current;
|
||||
unsigned long index;
|
||||
struct Linked_dir *next;
|
||||
} linked_dir;
|
||||
|
||||
|
||||
60
dir.c
60
dir.c
@@ -17,10 +17,11 @@ extern unsigned int settings;
|
||||
extern unsigned int file_modifiers;
|
||||
extern unsigned int color_count;
|
||||
extern unsigned int terminal_height;
|
||||
extern char *global_path;
|
||||
extern color *colors;
|
||||
int (*order_func)() = sort_natural;
|
||||
linked_dir *visited_dirs;
|
||||
linked_dir *current_dir;
|
||||
linked_dir *list_beginning;
|
||||
linked_dir *current_linked_dir;
|
||||
|
||||
|
||||
unsigned long get_dir_size(char *path){
|
||||
@@ -294,13 +295,58 @@ void print_dir(WINDOW *win, char print_info, dir *dir){
|
||||
|
||||
}
|
||||
}
|
||||
void dir_changed(){
|
||||
|
||||
char *path = getcwd(NULL, 0);
|
||||
current_linked_dir = list_beginning;
|
||||
while (current_linked_dir->next != NULL) {
|
||||
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||
break;
|
||||
} else {
|
||||
current_linked_dir = current_linked_dir->next;
|
||||
}
|
||||
}
|
||||
if(strcmp(current_linked_dir->path, path) == 0) {
|
||||
mid_dir.current_file = &mid_dir.file_list[current_linked_dir->index];
|
||||
|
||||
} else {
|
||||
/*this path should only ever happen on changing the path for the first time
|
||||
*at least i hope so*/
|
||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||
current_linked_dir->next->next = NULL;
|
||||
current_linked_dir->next->index = 0;
|
||||
}
|
||||
|
||||
}
|
||||
void change_dir(){
|
||||
|
||||
current_linked_dir = list_beginning;
|
||||
while (current_linked_dir->next != NULL) {
|
||||
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
||||
break;
|
||||
} else {
|
||||
current_linked_dir = current_linked_dir->next;
|
||||
}
|
||||
}
|
||||
if(strcmp(current_linked_dir->path, global_path) == 0) {
|
||||
current_linked_dir->index = mid_dir.current_file - mid_dir.file_list;
|
||||
} else {
|
||||
current_linked_dir->next = malloc(sizeof(linked_dir));
|
||||
current_linked_dir->next->path = malloc(strlen(global_path)+1);
|
||||
memcpy(current_linked_dir->next->path, global_path, strlen(global_path)+1);
|
||||
current_linked_dir->next->next = NULL;
|
||||
current_linked_dir->next->index = mid_dir.current_file - mid_dir.file_list;
|
||||
}
|
||||
}
|
||||
|
||||
void dir_init(){
|
||||
visited_dirs = malloc(sizeof(linked_dir));
|
||||
visited_dirs->path = getcwd(NULL, 0);
|
||||
visited_dirs->selected_file_current = 0;
|
||||
visited_dirs->next = NULL;
|
||||
current_dir = visited_dirs;
|
||||
list_beginning = malloc(sizeof(linked_dir));
|
||||
list_beginning->path = getcwd(NULL, 0);
|
||||
list_beginning->index = 0;
|
||||
list_beginning->next = NULL;
|
||||
current_linked_dir = list_beginning;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -163,15 +163,6 @@ void select_all(){
|
||||
}
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void dir_changed(){
|
||||
unsigned long i;
|
||||
|
||||
for(i = 0; i < mid_dir.file_count; i++) {
|
||||
mid_dir.file_list[i].status = 0;
|
||||
}
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY );
|
||||
}
|
||||
void move_down(unsigned long passes){
|
||||
|
||||
mid_dir.current_file += passes;
|
||||
@@ -193,6 +184,7 @@ void move_up(unsigned long passes){
|
||||
void move_left(unsigned long passes){
|
||||
unsigned long i;
|
||||
for (i = 0; i < passes; i++) {
|
||||
change_dir();
|
||||
if (chdir("..") != 0) {
|
||||
/* TODO(2025-07-09T00:30:05) fix */
|
||||
FAIL("move_left", "unhandled error of chdir");
|
||||
@@ -205,6 +197,7 @@ void move_left(unsigned long passes){
|
||||
void move_right(){
|
||||
|
||||
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||
change_dir();
|
||||
if (chdir(mid_dir.current_file->file_name) != 0) {
|
||||
/* TODO(2026-05-05T20:12:14) fix */
|
||||
FAIL("move_right", "unhandled error of chdir");
|
||||
|
||||
Reference in New Issue
Block a user