@@ -128,6 +128,14 @@ StlClickDefinition *tab_page_click_defs = NULL;
128128
129129long tab_page_click_defs_size = 0 ;
130130
131+ /// The last handle that was assigned to a ScreenGrid. 1 is reserved for
132+ /// the default_grid.
133+ /// TODO(utkarshme): Numbers can be recycled after grid destruction.
134+ static int last_handle = 1 ;
135+
136+ /// Whether to call "ui_call_grid_resize" in win_grid_alloc
137+ static int send_grid_resize ;
138+
131139#ifdef INCLUDE_GENERATED_DECLARATIONS
132140# include "screen.c.generated.h"
133141#endif
@@ -422,6 +430,7 @@ void update_screen(int type)
422430 win_redr_status (wp );
423431 }
424432 }
433+ send_grid_resize = false;
425434 end_search_hl ();
426435 // May need to redraw the popup menu.
427436 if (pum_drawn ()) {
@@ -654,7 +663,7 @@ static void win_update(win_T *wp)
654663
655664 type = wp -> w_redr_type ;
656665
657- window_grid_alloc (wp , false);
666+ win_grid_alloc (wp , false);
658667
659668 if (type == NOT_VALID ) {
660669 wp -> w_redr_status = TRUE;
@@ -2221,7 +2230,7 @@ win_line (
22212230 row = startrow ;
22222231
22232232 // allocate window grid if not already
2224- window_grid_alloc (wp , true);
2233+ win_grid_alloc (wp , true);
22252234
22262235 /*
22272236 * To speed up the loop below, set extra_check when there is linebreak,
@@ -5821,18 +5830,28 @@ int screen_valid(int doclear)
58215830/// (re)allocate a window grid if size changed
58225831/// If "doclear" is true, clear the screen if resized.
58235832// TODO(utkarshme): Think of a better name, place
5824- void window_grid_alloc (win_T * wp , int doclear )
5833+ void win_grid_alloc (win_T * wp , int doclear )
58255834{
5826- if (wp -> w_grid .ScreenLines != NULL
5827- && wp -> w_grid .Rows == wp -> w_height
5828- && wp -> w_grid .Columns == wp -> w_width ) {
5829- return ;
5830- }
5835+ if (wp -> w_grid .ScreenLines == NULL
5836+ || wp -> w_grid .Rows != wp -> w_height
5837+ || wp -> w_grid .Columns != wp -> w_width ) {
5838+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5839+
5840+ // only assign a grid handle if not already
5841+ if (wp -> w_grid .handle == 0 ) {
5842+ wp -> w_grid .handle = ++ last_handle ;
5843+ }
5844+
5845+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5846+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
58315847
5832- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5848+ wp -> w_grid .was_resized = true;
5849+ }
58335850
5834- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5835- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5851+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5852+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5853+ wp -> w_grid .was_resized = false;
5854+ }
58365855}
58375856
58385857/*
@@ -5926,6 +5945,7 @@ void screenalloc(bool doclear)
59265945
59275946 default_grid .OffsetRow = 0 ;
59285947 default_grid .OffsetColumn = 0 ;
5948+ default_grid .handle = 1 ;
59295949
59305950 must_redraw = CLEAR ; /* need to clear the screen later */
59315951 if (doclear )
@@ -5950,7 +5970,7 @@ void screenalloc(bool doclear)
59505970void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
59515971{
59525972 int new_row , old_row ;
5953- ScreenGrid new = { 0 } ;
5973+ ScreenGrid new = * grid ;
59545974
59555975 size_t ncells = (size_t )((rows + 1 ) * columns );
59565976 new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6237,7 +6257,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62376257 }
62386258 }
62396259
6240- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6260+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
62416261
62426262 return OK ;
62436263}
@@ -6289,7 +6309,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
62896309 }
62906310 }
62916311
6292- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6312+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
62936313
62946314 return OK ;
62956315}
@@ -7032,6 +7052,8 @@ void screen_resize(int width, int height)
70327052 default_grid .Rows = screen_Rows ;
70337053 default_grid .Columns = screen_Columns ;
70347054
7055+ send_grid_resize = true;
7056+
70357057 /* The window layout used to be adjusted here, but it now happens in
70367058 * screenalloc() (also invoked from screenclear()). That is because the
70377059 * "busy" check above may skip this, but not screenalloc(). */
0 commit comments