]> git.mdlowis.com Git - archive/afm.git/commitdiff
better page up/down scrolling
authorabellenir <a@bellenir.com>
Sat, 26 Jul 2014 09:16:01 +0000 (09:16 +0000)
committerabellenir <a@bellenir.com>
Sat, 26 Jul 2014 09:16:01 +0000 (09:16 +0000)
source/input.c
source/screen.c
source/screen.h
source/workdir.c
source/workdir.h

index cdaf0809c8fa2e268d233d580ef0d3b4a8dcf8ec..8b1f2a0801b932f8be384790262f9763e58f1721 100644 (file)
@@ -42,10 +42,10 @@ static void handle_scroll_to_bottom(void) {
        workdir_scroll_to_bot(state_get_focused_frame()->workdir);
 }
 static void handle_page_up(void){
-       workdir_jump_up(state_get_focused_frame()->workdir);
+       screen_frame_page_up(state_get_focused_frame());
 }
 static void handle_page_down(void){
-       workdir_jump_down(state_get_focused_frame()->workdir);
+       screen_frame_page_down(state_get_focused_frame());
 }
 
 
index ceeeb314994a2c0ef47bae0324d7f9dad828d3bc..8e2d8f42c45a1692f3e539b2f777298084c28a97 100644 (file)
@@ -172,4 +172,16 @@ void screen_frame_draw_files(frame_t* frame){
     }
 }
 
+int realrows(frame_t* p_frame){
+       int rows, cols;
+       getmaxyx(p_frame->p_win, rows, cols);
+       return rows - FrameTopBuffer - FrameBotBuffer;
+}
+void screen_frame_page_up(frame_t* p_frame){
+       workdir_set_idx(p_frame->workdir, p_frame->workdir->idx - realrows(p_frame));
+}
+
+void screen_frame_page_down(frame_t* p_frame){
+       workdir_set_idx(p_frame->workdir, p_frame->workdir->idx+realrows(p_frame));
+}
 
index 91bd67e6db89ef973a2addeda99b196aee5fe285..e1a24d466983a708886e858d4fde41b24656d1ec 100644 (file)
@@ -30,4 +30,7 @@ enum ColorPairs {
        DIRECTORY = 1
 };
 
+void screen_frame_page_up(frame_t* p_frame);
+void screen_frame_page_down(frame_t* p_frame);
+
 #endif /* SCREEN_H */
index 3993954647625634291a505b61e50d3281e53d44..dc7ee049851bbbaa50e5ca2faf12b509674b15d2 100644 (file)
@@ -50,7 +50,8 @@ void file_free(void* p_vfile){
 void workdir_set_idx(WorkDir_T* wd, int idx){
        wd->idx = idx;
        if(idx < 0) wd->idx = 0;
-       if(idx >= vec_size(wd->vfiles)) wd->idx = vec_size(wd->vfiles)-1;
+       else if(idx >= vec_size(wd->vfiles))
+               wd->idx = vec_size(wd->vfiles)-1;
        state_set_screen_dirty(true);
 }
 
@@ -70,14 +71,6 @@ void workdir_scroll_to_bot(WorkDir_T* wd){
        workdir_set_idx(wd, vec_size(wd->vfiles) - 1);
 }
 
-void workdir_jump_up(WorkDir_T* wd){
-       workdir_set_idx(wd, wd->idx - 20);
-}
-
-void workdir_jump_down(WorkDir_T* wd){
-       workdir_set_idx(wd, wd->idx + 20);
-}
-
 void workdir_cd(WorkDir_T* wd) {
     char* newpath = ((File_T*) vec_at(wd->vfiles, wd->idx))->path;
     if(is_dir(newpath)){
index 6226a3adbd75632461c428f92f16552daba4c0fe..9e436ba5d49450aee30e8eb61dec7515db484d32 100644 (file)
@@ -29,6 +29,8 @@ void workdir_prev(WorkDir_T*);
 
 void workdir_next(WorkDir_T*);
 
+void workdir_set_idx(WorkDir_T* wd, int idx);
+
 void workdir_cd(WorkDir_T*);
 
 void workdir_ls(WorkDir_T*);
@@ -39,7 +41,5 @@ void workdir_seek(WorkDir_T* wd, char* search);
 
 void workdir_scroll_to_top(WorkDir_T* wd);
 void workdir_scroll_to_bot(WorkDir_T* wd);
-void workdir_jump_down(WorkDir_T* wd);
-void workdir_jump_up(WorkDir_T* wd);
 
 #endif /* WORKDIR_H */