From f86f306ce28dd1daeaa40bb534f516b44d80a68f Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 11 Oct 2008 08:55:26 +0200 Subject: [PATCH] Fix some display bugs with read marker line, history, max prefix length, and chat refresh (bug #23153) Some info about bugs fixed: - when marker line (dotted) was on top of window (and not visible), this caused bug on last lines of buffer (not refreshed) - marker line is not set for a buffer after a switch, only if buffer it not displayed in other window - when we delete lines in a buffer (if lines > weechat.history.max_lines), we force a full refresh of chat if remaining lines is < to chat height and we compute again max prefix length for buffer (before max prefix length was always incremented, never decremented) --- src/gui/curses/gui-curses-chat.c | 23 +++++++++-------------- src/gui/curses/gui-curses-window.c | 3 ++- src/gui/gui-chat.c | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index fad732ea9..f6baece27 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -142,7 +142,7 @@ gui_chat_get_real_width (struct t_gui_window *window) } /* - * gui_chat_marker_for_line: return 1 if marker must be displayed before this + * gui_chat_marker_for_line: return 1 if marker must be displayed after this * line, or 0 if it must not */ @@ -158,7 +158,6 @@ gui_chat_marker_for_line (struct t_gui_buffer *buffer, struct t_gui_line *line) && (CONFIG_INTEGER(config_look_read_marker) != CONFIG_LOOK_READ_MARKER_DOTTED_LINE)) return 0; - line = line->prev_line; while (line) { if (buffer->last_read_line == line) @@ -167,7 +166,7 @@ gui_chat_marker_for_line (struct t_gui_buffer *buffer, struct t_gui_line *line) if (line->displayed) break; - line = line->prev_line; + line = line->next_line; } return 0; } @@ -804,14 +803,6 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, marker_line = gui_chat_marker_for_line (window->buffer, line); - if (marker_line) - { - gui_chat_display_horizontal_line (window, simulate); - gui_chat_display_new_line (window, num_lines, count, - &lines_displayed, simulate); - lines_displayed--; - } - /* display time and prefix */ gui_chat_display_time_and_prefix (window, line, num_lines, count, &lines_displayed, simulate); @@ -904,6 +895,13 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, } } + if (marker_line && gui_chat_get_next_line_displayed (line)) + { + gui_chat_display_horizontal_line (window, simulate); + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + } + if (simulate) { window->win_chat_cursor_x = x; @@ -940,9 +938,6 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, } } - if (marker_line) - lines_displayed++; - return lines_displayed; } diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index bc0a3f7ca..a72a5f4e0 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -633,7 +633,8 @@ gui_window_switch_to_buffer (struct t_gui_window *window, { window->start_line = NULL; window->start_line_pos = 0; - window->buffer->last_read_line = window->buffer->last_line; + if (window->buffer->num_displayed == 0) + window->buffer->last_read_line = window->buffer->last_line; if (buffer->last_read_line == buffer->last_line) buffer->last_read_line = NULL; gui_previous_buffer = window->buffer; diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index df9c0006f..c52164e56 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -652,8 +652,12 @@ gui_chat_line_has_highlight (struct t_gui_buffer *buffer, void gui_chat_line_free (struct t_gui_buffer *buffer, struct t_gui_line *line) { + int update_prefix_max_length; + struct t_gui_line *ptr_line; struct t_gui_window *ptr_win; + update_prefix_max_length = (line->prefix_length == buffer->prefix_max_length); + /* reset scroll for any window starting with this line */ for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { @@ -689,6 +693,17 @@ gui_chat_line_free (struct t_gui_buffer *buffer, struct t_gui_line *line) free (line); buffer->lines_count--; + + if (update_prefix_max_length) + { + buffer->prefix_max_length = 0; + for (ptr_line = buffer->lines; ptr_line; + ptr_line = ptr_line->next_line) + { + if (ptr_line->prefix_length > buffer->prefix_max_length) + buffer->prefix_max_length = ptr_line->prefix_length; + } + } } /* @@ -739,6 +754,7 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, const char *prefix, const char *message) { struct t_gui_line *new_line; + struct t_gui_window *ptr_win; new_line = malloc (sizeof (*new_line)); if (!new_line) @@ -811,6 +827,15 @@ gui_chat_line_add (struct t_gui_buffer *buffer, time_t date, && (buffer->lines_count > CONFIG_INTEGER(config_history_max_lines))) { gui_chat_line_free (buffer, buffer->lines); + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + if ((ptr_win->buffer == buffer) + && (buffer->lines_count < ptr_win->win_chat_height)) + { + gui_buffer_ask_chat_refresh (buffer, 2); + break; + } + } } }