@@ -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 ()) {
@@ -661,7 +670,7 @@ static void win_update(win_T *wp)
661670
662671 type = wp -> w_redr_type ;
663672
664- window_grid_alloc (wp , false);
673+ win_grid_alloc (wp , false);
665674
666675 if (type == NOT_VALID ) {
667676 wp -> w_redr_status = TRUE;
@@ -2228,7 +2237,7 @@ win_line (
22282237 row = startrow ;
22292238
22302239 // allocate window grid if not already
2231- window_grid_alloc (wp , true);
2240+ win_grid_alloc (wp , true);
22322241
22332242 /*
22342243 * To speed up the loop below, set extra_check when there is linebreak,
@@ -5838,18 +5847,28 @@ int screen_valid(int doclear)
58385847/// (re)allocate a window grid if size changed
58395848/// If "doclear" is true, clear the screen if resized.
58405849// TODO(utkarshme): Think of a better name, place
5841- void window_grid_alloc (win_T * wp , int doclear )
5850+ void win_grid_alloc (win_T * wp , int doclear )
58425851{
5843- if (wp -> w_grid .ScreenLines != NULL
5844- && wp -> w_grid .Rows == wp -> w_height
5845- && wp -> w_grid .Columns == wp -> w_width ) {
5846- return ;
5847- }
5852+ if (wp -> w_grid .ScreenLines == NULL
5853+ || wp -> w_grid .Rows != wp -> w_height
5854+ || wp -> w_grid .Columns != wp -> w_width ) {
5855+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5856+
5857+ // only assign a grid handle if not already
5858+ if (wp -> w_grid .handle == 0 ) {
5859+ wp -> w_grid .handle = ++ last_handle ;
5860+ }
5861+
5862+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5863+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
58485864
5849- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5865+ wp -> w_grid .was_resized = true;
5866+ }
58505867
5851- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5852- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5868+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5869+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5870+ wp -> w_grid .was_resized = false;
5871+ }
58535872}
58545873
58555874/*
@@ -5943,6 +5962,7 @@ void screenalloc(bool doclear)
59435962
59445963 default_grid .OffsetRow = 0 ;
59455964 default_grid .OffsetColumn = 0 ;
5965+ default_grid .handle = 1 ;
59465966
59475967 must_redraw = CLEAR ; /* need to clear the screen later */
59485968 if (doclear )
@@ -5967,7 +5987,7 @@ void screenalloc(bool doclear)
59675987void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
59685988{
59695989 int new_row , old_row ;
5970- ScreenGrid new = { 0 } ;
5990+ ScreenGrid new = * grid ;
59715991
59725992 size_t ncells = (size_t )((rows + 1 ) * columns );
59735993 new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6254,7 +6274,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62546274 }
62556275 }
62566276
6257- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6277+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
62586278
62596279 return OK ;
62606280}
@@ -6306,7 +6326,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
63066326 }
63076327 }
63086328
6309- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6329+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
63106330
63116331 return OK ;
63126332}
@@ -7059,6 +7079,8 @@ void screen_resize(int width, int height)
70597079 default_grid .Rows = screen_Rows ;
70607080 default_grid .Columns = screen_Columns ;
70617081
7082+ send_grid_resize = true;
7083+
70627084 /* The window layout used to be adjusted here, but it now happens in
70637085 * screenalloc() (also invoked from screenclear()). That is because the
70647086 * "busy" check above may skip this, but not screenalloc(). */
0 commit comments