@@ -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,
@@ -5831,18 +5840,28 @@ int screen_valid(int doclear)
58315840/// (re)allocate a window grid if size changed
58325841/// If "doclear" is true, clear the screen if resized.
58335842// TODO(utkarshme): Think of a better name, place
5834- void window_grid_alloc (win_T * wp , int doclear )
5843+ void win_grid_alloc (win_T * wp , int doclear )
58355844{
5836- if (wp -> w_grid .ScreenLines != NULL
5837- && wp -> w_grid .Rows == wp -> w_height
5838- && wp -> w_grid .Columns == wp -> w_width ) {
5839- return ;
5840- }
5845+ if (wp -> w_grid .ScreenLines == NULL
5846+ || wp -> w_grid .Rows != wp -> w_height
5847+ || wp -> w_grid .Columns != wp -> w_width ) {
5848+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5849+
5850+ // only assign a grid handle if not already
5851+ if (wp -> w_grid .handle == 0 ) {
5852+ wp -> w_grid .handle = ++ last_handle ;
5853+ }
5854+
5855+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5856+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
58415857
5842- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5858+ wp -> w_grid .was_resized = true;
5859+ }
58435860
5844- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5845- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5861+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5862+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5863+ wp -> w_grid .was_resized = false;
5864+ }
58465865}
58475866
58485867/*
@@ -5936,6 +5955,7 @@ void screenalloc(bool doclear)
59365955
59375956 default_grid .OffsetRow = 0 ;
59385957 default_grid .OffsetColumn = 0 ;
5958+ default_grid .handle = 1 ;
59395959
59405960 must_redraw = CLEAR ; /* need to clear the screen later */
59415961 if (doclear )
@@ -5960,7 +5980,7 @@ void screenalloc(bool doclear)
59605980void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
59615981{
59625982 int new_row , old_row ;
5963- ScreenGrid new = { 0 } ;
5983+ ScreenGrid new = * grid ;
59645984
59655985 size_t ncells = (size_t )((rows + 1 ) * columns );
59665986 new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6247,7 +6267,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62476267 }
62486268 }
62496269
6250- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6270+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
62516271
62526272 return OK ;
62536273}
@@ -6299,7 +6319,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
62996319 }
63006320 }
63016321
6302- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6322+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
63036323
63046324 return OK ;
63056325}
@@ -7052,6 +7072,8 @@ void screen_resize(int width, int height)
70527072 default_grid .Rows = screen_Rows ;
70537073 default_grid .Columns = screen_Columns ;
70547074
7075+ send_grid_resize = true;
7076+
70557077 /* The window layout used to be adjusted here, but it now happens in
70567078 * screenalloc() (also invoked from screenclear()). That is because the
70577079 * "busy" check above may skip this, but not screenalloc(). */
0 commit comments