multigrid: various cleanup (types, unused parameters)

Handle the rare case of full highlight table properly
This commit is contained in:
Björn Linse
2018-12-23 14:12:56 +01:00
parent 44b8e58f33
commit 820c81e638
6 changed files with 33 additions and 26 deletions

View File

@@ -1494,7 +1494,7 @@ void edit_putchar(int c, int highlight)
{ {
int attr; int attr;
if (default_grid.ScreenLines != NULL) { if (curwin->w_grid.ScreenLines != NULL || default_grid.ScreenLines != NULL) {
update_topline(); // just in case w_topline isn't valid update_topline(); // just in case w_topline isn't valid
validate_cursor(); validate_cursor();
if (highlight) { if (highlight) {

View File

@@ -98,7 +98,7 @@ static int get_attr_entry(HlEntry entry)
return id; return id;
} }
/// When a UI connects, we need to send it the table of higlights used so far. /// When a UI connects, we need to send it the table of highlights used so far.
void ui_send_all_hls(UI *ui) void ui_send_all_hls(UI *ui)
{ {
for (size_t i = 1; i < kv_size(attr_entries); i++) { for (size_t i = 1; i < kv_size(attr_entries); i++) {
@@ -212,13 +212,7 @@ void clear_hl_tables(bool reinit)
map_clear(int, int)(combine_attr_entries); map_clear(int, int)(combine_attr_entries);
highlight_attr_set_all(); highlight_attr_set_all();
highlight_changed(); highlight_changed();
redraw_all_later(NOT_VALID); screen_invalidate_highlights();
if (default_grid.ScreenAttrs) {
// the meaning of 0 doesn't change anyway
// but the rest must be retransmitted
memset(default_grid.ScreenAttrs, 0, sizeof(*default_grid.ScreenAttrs)
* (size_t)(default_grid.Rows * default_grid.Columns));
}
} else { } else {
kv_destroy(attr_entries); kv_destroy(attr_entries);
map_free(HlEntry, int)(attr_entry_ids); map_free(HlEntry, int)(attr_entry_ids);

View File

@@ -556,14 +556,6 @@ size_t mb_string2cells(const char_u *str)
return clen; return clen;
} }
/// Return number of display cells for char at ScreenLines[off].
/// We make sure that the offset used is less than "max_off".
int utf_off2cells(ScreenGrid *grid, unsigned off, unsigned max_off)
{
return (off + 1 < max_off
&& grid->ScreenLines[off + 1][0] == 0) ? 2 : 1;
}
/// Convert a UTF-8 byte sequence to a wide character /// Convert a UTF-8 byte sequence to a wide character
/// ///
/// If the sequence is illegal or truncated by a NUL then the first byte is /// If the sequence is illegal or truncated by a NUL then the first byte is

View File

@@ -151,7 +151,7 @@ void update_topline(void)
long save_so = p_so; long save_so = p_so;
// need to have w_grid.Rows/Columns updated // need to have w_grid.Rows/Columns updated
win_grid_alloc(curwin, false); win_grid_alloc(curwin);
// If there is no valid screen and when the window height is zero just use // If there is no valid screen and when the window height is zero just use
// the cursor line. // the cursor line.
@@ -529,7 +529,7 @@ int cursor_valid(void)
*/ */
void validate_cursor(void) void validate_cursor(void)
{ {
win_grid_alloc(curwin, false); // we need to have w_grid.Rows/Columns updated win_grid_alloc(curwin); // we need to have w_grid.Rows/Columns updated
check_cursor_moved(curwin); check_cursor_moved(curwin);
if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW)) if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW))
curs_columns(true); curs_columns(true);

View File

@@ -146,7 +146,10 @@ typedef struct {
#define LINE_STATE(p) { p, 0, 0 } #define LINE_STATE(p) { p, 0, 0 }
/// Whether to call "ui_call_grid_resize" in win_grid_alloc /// Whether to call "ui_call_grid_resize" in win_grid_alloc
static int send_grid_resize; static bool send_grid_resize = false;
/// Highlight ids are no longer valid. Force retransmission
static bool highlights_invalid = false;
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "screen.c.generated.h" # include "screen.c.generated.h"
@@ -184,6 +187,12 @@ void redraw_all_later(int type)
} }
} }
void screen_invalidate_highlights(void)
{
redraw_all_later(NOT_VALID);
highlights_invalid = true;
}
/* /*
* Mark all windows that are editing the current buffer to be updated later. * Mark all windows that are editing the current buffer to be updated later.
*/ */
@@ -353,6 +362,8 @@ void update_screen(int type)
type = NOT_VALID; type = NOT_VALID;
// must_redraw may be set indirectly, avoid another redraw later // must_redraw may be set indirectly, avoid another redraw later
must_redraw = 0; must_redraw = 0;
} else if (highlights_invalid) {
grid_invalidate(&default_grid);
} }
if (clear_cmdline) /* going to clear cmdline (done below) */ if (clear_cmdline) /* going to clear cmdline (done below) */
@@ -439,6 +450,7 @@ void update_screen(int type)
} }
} }
send_grid_resize = false; send_grid_resize = false;
highlights_invalid = false;
end_search_hl(); end_search_hl();
// May need to redraw the popup menu. // May need to redraw the popup menu.
if (pum_drawn()) { if (pum_drawn()) {
@@ -522,7 +534,7 @@ void update_single_line(win_T *wp, linenr_T lnum)
prepare_search_hl(wp, lnum); prepare_search_hl(wp, lnum);
update_window_hl(wp, false); update_window_hl(wp, false);
// allocate window grid if not already // allocate window grid if not already
win_grid_alloc(wp, false); win_grid_alloc(wp);
win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, false, false); win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, false, false);
end_search_hl(); end_search_hl();
break; break;
@@ -680,7 +692,7 @@ static void win_update(win_T *wp)
type = wp->w_redr_type; type = wp->w_redr_type;
win_grid_alloc(wp, false); win_grid_alloc(wp);
if (type >= NOT_VALID) { if (type >= NOT_VALID) {
wp->w_redr_status = true; wp->w_redr_status = true;
@@ -5984,7 +5996,7 @@ int screen_valid(int doclear)
/// ///
/// If "doclear" is true, don't try to copy from the old grid rather clear the /// If "doclear" is true, don't try to copy from the old grid rather clear the
/// resized grid. /// resized grid.
void win_grid_alloc(win_T *wp, int doclear) void win_grid_alloc(win_T *wp)
{ {
ScreenGrid *grid = &wp->w_grid; ScreenGrid *grid = &wp->w_grid;
int rows = grid->internal_rows; int rows = grid->internal_rows;
@@ -6002,11 +6014,15 @@ void win_grid_alloc(win_T *wp, int doclear)
bool want_allocation = ui_is_external(kUIMultigrid); bool want_allocation = ui_is_external(kUIMultigrid);
bool has_allocation = (grid->ScreenLines != NULL); bool has_allocation = (grid->ScreenLines != NULL);
if (want_allocation && has_allocation && highlights_invalid) {
grid_invalidate(grid);
}
if ((has_allocation != want_allocation) if ((has_allocation != want_allocation)
|| grid->Rows != rows || grid->Rows != rows
|| grid->Columns != columns) { || grid->Columns != columns) {
if (want_allocation) { if (want_allocation) {
grid_alloc(grid, rows, columns, !doclear); grid_alloc(grid, rows, columns, true);
win_free_lsize(wp); win_free_lsize(wp);
win_alloc_lines(wp); win_alloc_lines(wp);
} else { } else {
@@ -6289,6 +6305,13 @@ static void grid_clear_line(ScreenGrid *grid, unsigned off, int width,
(void)memset(grid->ScreenAttrs + off, fill, (size_t)width * sizeof(sattr_T)); (void)memset(grid->ScreenAttrs + off, fill, (size_t)width * sizeof(sattr_T));
} }
static void grid_invalidate(ScreenGrid *grid)
{
(void)memset(grid->ScreenAttrs, -1,
grid->Rows * grid->Columns * sizeof(sattr_T));
}
/// Copy part of a Screenline for vertically split window. /// Copy part of a Screenline for vertically split window.
static void linecopy(ScreenGrid *grid, int to, int from, int col, int width) static void linecopy(ScreenGrid *grid, int to, int from, int col, int width)
{ {

View File

@@ -4299,7 +4299,6 @@ void win_setheight_win(int height, win_T *win)
} }
frame_setheight(win->w_frame, height + win->w_status_height); frame_setheight(win->w_frame, height + win->w_status_height);
win_grid_alloc(win, false);
/* recompute the window positions */ /* recompute the window positions */
row = win_comp_pos(); row = win_comp_pos();
@@ -4497,7 +4496,6 @@ void win_setwidth_win(int width, win_T *wp)
} }
frame_setwidth(wp->w_frame, width + wp->w_vsep_width); frame_setwidth(wp->w_frame, width + wp->w_vsep_width);
win_grid_alloc(wp, false);
/* recompute the window positions */ /* recompute the window positions */
(void)win_comp_pos(); (void)win_comp_pos();