@@ -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
@@ -420,6 +428,7 @@ void update_screen(int type)
420428 win_redr_status (wp );
421429 }
422430 }
431+ send_grid_resize = false;
423432 end_search_hl ();
424433 // May need to redraw the popup menu.
425434 if (pum_drawn ()) {
@@ -652,7 +661,7 @@ static void win_update(win_T *wp)
652661
653662 type = wp -> w_redr_type ;
654663
655- window_grid_alloc (wp , false);
664+ win_grid_alloc (wp , false);
656665
657666 if (type == NOT_VALID ) {
658667 wp -> w_redr_status = TRUE;
@@ -2218,7 +2227,7 @@ win_line (
22182227 row = startrow ;
22192228
22202229 // allocate window grid if not already
2221- window_grid_alloc (wp , true);
2230+ win_grid_alloc (wp , true);
22222231
22232232 /*
22242233 * To speed up the loop below, set extra_check when there is linebreak,
@@ -5807,18 +5816,28 @@ int screen_valid(int doclear)
58075816/// (re)allocate a window grid if size changed
58085817/// If "doclear" is true, clear the screen if resized.
58095818// TODO(utkarshme): Think of a better name, place
5810- void window_grid_alloc (win_T * wp , int doclear )
5819+ void win_grid_alloc (win_T * wp , int doclear )
58115820{
5812- if (wp -> w_grid .ScreenLines != NULL
5813- && wp -> w_grid .Rows == wp -> w_height
5814- && wp -> w_grid .Columns == wp -> w_width ) {
5815- return ;
5816- }
5821+ if (wp -> w_grid .ScreenLines == NULL
5822+ || wp -> w_grid .Rows != wp -> w_height
5823+ || wp -> w_grid .Columns != wp -> w_width ) {
5824+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5825+
5826+ // only assign a grid handle if not already
5827+ if (wp -> w_grid .handle == 0 ) {
5828+ wp -> w_grid .handle = ++ last_handle ;
5829+ }
5830+
5831+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5832+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
58175833
5818- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5834+ wp -> w_grid .was_resized = true;
5835+ }
58195836
5820- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5821- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5837+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5838+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5839+ wp -> w_grid .was_resized = false;
5840+ }
58225841}
58235842
58245843/*
@@ -5912,6 +5931,7 @@ void screenalloc(bool doclear)
59125931
59135932 default_grid .OffsetRow = 0 ;
59145933 default_grid .OffsetColumn = 0 ;
5934+ default_grid .handle = 1 ;
59155935
59165936 must_redraw = CLEAR ; /* need to clear the screen later */
59175937 if (doclear )
@@ -5936,7 +5956,7 @@ void screenalloc(bool doclear)
59365956void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
59375957{
59385958 int new_row , old_row ;
5939- ScreenGrid new = { 0 } ;
5959+ ScreenGrid new = * grid ;
59405960
59415961 size_t ncells = (size_t )((rows + 1 ) * columns );
59425962 new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6223,7 +6243,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
62236243 }
62246244 }
62256245
6226- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6246+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
62276247
62286248 return OK ;
62296249}
@@ -6275,7 +6295,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
62756295 }
62766296 }
62776297
6278- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6298+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
62796299
62806300 return OK ;
62816301}
@@ -7018,6 +7038,8 @@ void screen_resize(int width, int height)
70187038 default_grid .Rows = screen_Rows ;
70197039 default_grid .Columns = screen_Columns ;
70207040
7041+ send_grid_resize = true;
7042+
70217043 // TODO(bfredl): update default colors when they changed, NOT on resize.
70227044 ui_default_colors_set ();
70237045
0 commit comments