]> git.mdlowis.com Git - archive/afm.git/commitdiff
dont redraw whole window to change highlighted item
authora bellenir <a@bellenir.com>
Mon, 28 Jul 2014 07:49:47 +0000 (07:49 +0000)
committera bellenir <a@bellenir.com>
Mon, 28 Jul 2014 07:49:47 +0000 (07:49 +0000)
source/frame.c
source/workdir.c

index 17f661157374230c59596eec91d37612d65f1a8c..17b36344a2f4a851fc87a7183b8f38c65f5b8235 100644 (file)
@@ -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);
        }
 }
index 37a0b01daa5e421fbb5e9ae29201c8d692557cf1..953125208703df77fc13b26a0cf28a9e6d31550c 100644 (file)
@@ -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) {