diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index b863ab1d324ded..820b523f5b9a35 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -262,6 +262,10 @@ static void remote_ui_grid_resize(UI *ui, Integer grid, Array args = ARRAY_DICT_INIT; if (ui->ui_ext[kUIMultigrid]) { ADD(args, INTEGER_OBJ(grid)); + } else if (grid != 1) { + // calling grid_resize with a grid other than the global when + // the remote ui is not managing grids should not send the event + return; } ADD(args, INTEGER_OBJ(width)); ADD(args, INTEGER_OBJ(height)); diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 784d9b5f8041fc..271e19e1df8b8b 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -128,6 +128,11 @@ StlClickDefinition *tab_page_click_defs = NULL; long tab_page_click_defs_size = 0; +/// The last handle that was assigned to a ScreenGrid. 1 is reserved for +/// the default_grid. +/// TODO(utkarshme): Numbers can be recycled after grid destruction. +static int last_handle = 1; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "screen.c.generated.h" #endif @@ -5824,6 +5829,12 @@ void window_grid_alloc(win_T *wp, int doclear) grid_alloc(&wp->w_grid, wp->w_height, wp->w_width, doclear); + // only assign a grid handle if not already + if (wp->w_grid.handle == 0) { + wp->w_grid.handle = ++last_handle; + ui_call_grid_resize(wp->w_grid.handle, wp->w_grid.Columns, wp->w_grid.Rows); + } + wp->w_grid.OffsetRow = wp->w_winrow; wp->w_grid.OffsetColumn = wp->w_wincol; } @@ -5919,6 +5930,7 @@ void screenalloc(bool doclear) default_grid.OffsetRow = 0; default_grid.OffsetColumn = 0; + default_grid.handle = 1; must_redraw = CLEAR; /* need to clear the screen later */ if (doclear) @@ -6230,7 +6242,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, } } - ui_call_grid_scroll(1, row, end, col, col+width, -line_count, 0); + ui_call_grid_scroll(grid->handle, row, end, col, col+width, -line_count, 0); return OK; } @@ -6282,7 +6294,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, } } - ui_call_grid_scroll(1, row, end, col, col+width, line_count, 0); + ui_call_grid_scroll(grid->handle, row, end, col, col+width, line_count, 0); return OK; } diff --git a/src/nvim/types.h b/src/nvim/types.h index 264c53a725990c..2e6735e99dc55b 100644 --- a/src/nvim/types.h +++ b/src/nvim/types.h @@ -23,7 +23,10 @@ typedef char_u schar_T[(MAX_MCO+1) * 4 + 1]; typedef int16_t sattr_T; // TODO(bfredl): find me a good home +typedef unsigned int GridHandle; typedef struct { + GridHandle handle; + schar_T *ScreenLines; sattr_T *ScreenAttrs; unsigned *LineOffset; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 1a0e3acd78ff3b..f7d9215ec7d343 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -314,17 +314,16 @@ void ui_set_ext_option(UI *ui, UIExtension ext, bool active) void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, int clearattr) { - size_t off = grid->LineOffset[row] + (size_t)startcol; - - UI_CALL(raw_line, 1, - grid->OffsetRow + row, - grid->OffsetColumn + startcol, - grid->OffsetColumn + endcol, - grid->OffsetColumn + clearcol, - clearattr, - grid->ScreenLines + off, - grid->ScreenAttrs + off); - + size_t off = grid->LineOffset[row] + (size_t)startcol; + int row_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetRow; + int col_off = ui_is_external(kUIMultigrid) ? 0 : grid->OffsetColumn; + + UI_CALL(raw_line, grid->handle, + row_off + row, + col_off + startcol, + col_off + endcol, + col_off + clearcol, + clearattr, grid->ScreenLines + off, grid->ScreenAttrs + off); if (p_wd) { // 'writedelay': flush & delay each time. ui_flush(); uint64_t wd = (uint64_t)labs(p_wd);