From 02de38c354ec49d12498bf19e058c55a38d6a846 Mon Sep 17 00:00:00 2001 From: a bellenir Date: Mon, 28 Jul 2014 08:45:45 +0000 Subject: [PATCH] fix highlighting for new windows & fix segfault when closing windows --- source/frame.c | 8 +++----- source/screen.c | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/frame.c b/source/frame.c index 17b3634..1b61861 100644 --- a/source/frame.c +++ b/source/frame.c @@ -102,9 +102,6 @@ void frame_draw_files(Frame_T* frame){ while (file_i < vec_size(frame->workdir->vfiles)){ File_T* file = (File_T*)vec_at(frame->workdir->vfiles, file_i); bool dir = is_dir(file->path); - if(frame == state_get_focused_frame() && file_i == frame->workdir->idx){ - wattron(frame->p_win, A_STANDOUT | A_BOLD); - } if(dir) wattron(frame->p_win, COLOR_PAIR(DIRECTORY)); mvwaddnstr(frame->p_win, frame_i, 1, file->name, cols-2); frame_i++; @@ -116,6 +113,7 @@ void frame_draw_files(Frame_T* frame){ file_i++; if((frame_i+FrameBotBuffer) > rows) break; } + if(frame == state_get_focused_frame()) frame_set_highlighting(frame, true, false); } @@ -124,9 +122,9 @@ void frame_set_highlighting(Frame_T* frame, bool highlight, bool refresh_win){ 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); + short color = (file && 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(file && 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/screen.c b/source/screen.c index d452942..ab6d982 100644 --- a/source/screen.c +++ b/source/screen.c @@ -62,8 +62,10 @@ static int get_focused_frame_index(void){ void screen_close(void) { if (Frame_List->head != Frame_List->tail) { int i = get_focused_frame_index(); - list_node_t* new_focus = state_get_focused_node()->next; if(i >= 0){ /* negative if node not found */ + list_node_t* doomed_node = state_get_focused_node(); + mem_retain(doomed_node); + list_node_t* new_focus = doomed_node->next; /* TODO: add function to list that allows removing with node pointer instead of just index */ list_delete(Frame_List, i); // new_focus will be null if rm-d tail: set it to new tail @@ -71,6 +73,7 @@ void screen_close(void) { state_set_focused_node(new_focus); state_set_screen_dirty(true); state_set_screen_resized(true); + mem_release(doomed_node); } } } -- 2.52.0