From de32db0b9d5c584c7c8a31001d72bab6e8969419 Mon Sep 17 00:00:00 2001 From: abellenir Date: Sat, 26 Jul 2014 09:16:01 +0000 Subject: [PATCH] better page up/down scrolling --- source/input.c | 4 ++-- source/screen.c | 12 ++++++++++++ source/screen.h | 3 +++ source/workdir.c | 11 ++--------- source/workdir.h | 4 ++-- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/source/input.c b/source/input.c index cdaf080..8b1f2a0 100644 --- a/source/input.c +++ b/source/input.c @@ -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()); } diff --git a/source/screen.c b/source/screen.c index ceeeb31..8e2d8f4 100644 --- a/source/screen.c +++ b/source/screen.c @@ -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)); +} diff --git a/source/screen.h b/source/screen.h index 91bd67e..e1a24d4 100644 --- a/source/screen.h +++ b/source/screen.h @@ -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 */ diff --git a/source/workdir.c b/source/workdir.c index 3993954..dc7ee04 100644 --- a/source/workdir.c +++ b/source/workdir.c @@ -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)){ diff --git a/source/workdir.h b/source/workdir.h index 6226a3a..9e436ba 100644 --- a/source/workdir.h +++ b/source/workdir.h @@ -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 */ -- 2.54.0