From e841edbd6b59afbae6c4d99865102eb4f64fce8d Mon Sep 17 00:00:00 2001 From: a bellenir Date: Mon, 28 Jul 2014 07:49:47 +0000 Subject: [PATCH] dont redraw whole window to change highlighted item --- source/frame.c | 19 +++++++++++++------ source/workdir.c | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/source/frame.c b/source/frame.c index 17f6611..17b3634 100644 --- a/source/frame.c +++ b/source/frame.c @@ -47,24 +47,30 @@ static void frame_free(void* p_frame_ptr) { if(p_frame->workdir) mem_release(p_frame->workdir); } -static int count_double_lines(Frame_T* p_frame){ +static int count_double_lines_to_idx(Frame_T* p_frame, bool inclusive){ int count = 0; - for(int i = p_frame->top_index; i <= p_frame->workdir->idx; i++) + int target = p_frame->workdir->idx + (inclusive ? 1 : 0); + for(int i = p_frame->top_index; i < target; i++) if (((File_T*)vec_at(p_frame->workdir->vfiles, i))->expanded) count++; return count; } -static void frame_scroll(Frame_T* p_frame){ +static bool frame_scroll(Frame_T* p_frame){ int rows,cols; + bool changed = false; getmaxyx(p_frame->p_win, rows, cols); (void) cols; if(p_frame->workdir->idx < p_frame->top_index){ p_frame->top_index = p_frame->workdir->idx; + changed = true; }else{ - int doublelines = count_double_lines(p_frame); - if (p_frame->top_index < doublelines+p_frame->workdir->idx-(rows-FrameTopBuffer-FrameBotBuffer)) + int doublelines = count_double_lines_to_idx(p_frame, true); + if (p_frame->top_index < doublelines+p_frame->workdir->idx-(rows-FrameTopBuffer-FrameBotBuffer)){ p_frame->top_index = doublelines+p_frame->workdir->idx-(rows-FrameTopBuffer-FrameBotBuffer); + changed = true; + } } + return changed; } int realrows(Frame_T* p_frame){ @@ -115,12 +121,13 @@ void frame_draw_files(Frame_T* frame){ void frame_set_highlighting(Frame_T* frame, bool highlight, bool refresh_win){ if(frame){ - int line = FrameTopBuffer + frame->workdir->idx - frame->top_index; + int line = FrameTopBuffer + count_double_lines_to_idx(frame, false) + frame->workdir->idx - frame->top_index; attr_t newattr= highlight ? (A_STANDOUT|A_BOLD) : A_NORMAL; File_T* file = (File_T*) vec_at(frame->workdir->vfiles, frame->workdir->idx); short color = (is_dir(file->path) ? DIRECTORY : 0); mvwchgat(frame->p_win, line, 0, -1, newattr, color, NULL); if(file->expanded) mvwchgat(frame->p_win, line+1, color, -1, newattr, 0, NULL); + if(frame_scroll(frame)) state_set_screen_dirty(true); if(refresh_win) wrefresh(frame->p_win); } } diff --git a/source/workdir.c b/source/workdir.c index 37a0b01..9531252 100644 --- a/source/workdir.c +++ b/source/workdir.c @@ -53,11 +53,12 @@ void file_free(void* p_vfile){ } void workdir_set_idx(WorkDir_T* wd, int idx){ + frame_set_highlighting(state_get_focused_frame(), false, false); wd->idx = idx; if(idx < 0) wd->idx = 0; else if(idx >= vec_size(wd->vfiles)) wd->idx = vec_size(wd->vfiles)-1; - state_set_screen_dirty(true); + frame_set_highlighting(state_get_focused_frame(), true, true); } void workdir_next(WorkDir_T* wd) { -- 2.52.0