@@ -128,6 +128,14 @@ StlClickDefinition *tab_page_click_defs = NULL;
128
128
129
129
long tab_page_click_defs_size = 0 ;
130
130
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
+
131
139
#ifdef INCLUDE_GENERATED_DECLARATIONS
132
140
# include "screen.c.generated.h"
133
141
#endif
@@ -420,6 +428,7 @@ void update_screen(int type)
420
428
win_redr_status (wp );
421
429
}
422
430
}
431
+ send_grid_resize = false;
423
432
end_search_hl ();
424
433
// May need to redraw the popup menu.
425
434
if (pum_drawn ()) {
@@ -652,7 +661,7 @@ static void win_update(win_T *wp)
652
661
653
662
type = wp -> w_redr_type ;
654
663
655
- window_grid_alloc (wp , false);
664
+ win_grid_alloc (wp , false);
656
665
657
666
if (type == NOT_VALID ) {
658
667
wp -> w_redr_status = TRUE;
@@ -2218,7 +2227,7 @@ win_line (
2218
2227
row = startrow ;
2219
2228
2220
2229
// allocate window grid if not already
2221
- window_grid_alloc (wp , true);
2230
+ win_grid_alloc (wp , true);
2222
2231
2223
2232
/*
2224
2233
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5807,18 +5816,28 @@ int screen_valid(int doclear)
5807
5816
/// (re)allocate a window grid if size changed
5808
5817
/// If "doclear" is true, clear the screen if resized.
5809
5818
// 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 )
5811
5820
{
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 ;
5817
5833
5818
- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5834
+ wp -> w_grid .was_resized = true;
5835
+ }
5819
5836
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
+ }
5822
5841
}
5823
5842
5824
5843
/*
@@ -5912,6 +5931,7 @@ void screenalloc(bool doclear)
5912
5931
5913
5932
default_grid .OffsetRow = 0 ;
5914
5933
default_grid .OffsetColumn = 0 ;
5934
+ default_grid .handle = 1 ;
5915
5935
5916
5936
must_redraw = CLEAR ; /* need to clear the screen later */
5917
5937
if (doclear )
@@ -5936,7 +5956,7 @@ void screenalloc(bool doclear)
5936
5956
void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
5937
5957
{
5938
5958
int new_row , old_row ;
5939
- ScreenGrid new = { 0 } ;
5959
+ ScreenGrid new = * grid ;
5940
5960
5941
5961
size_t ncells = (size_t )((rows + 1 ) * columns );
5942
5962
new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6223,7 +6243,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
6223
6243
}
6224
6244
}
6225
6245
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 );
6227
6247
6228
6248
return OK ;
6229
6249
}
@@ -6275,7 +6295,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
6275
6295
}
6276
6296
}
6277
6297
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 );
6279
6299
6280
6300
return OK ;
6281
6301
}
@@ -7018,6 +7038,8 @@ void screen_resize(int width, int height)
7018
7038
default_grid .Rows = screen_Rows ;
7019
7039
default_grid .Columns = screen_Columns ;
7020
7040
7041
+ send_grid_resize = true;
7042
+
7021
7043
// TODO(bfredl): update default colors when they changed, NOT on resize.
7022
7044
ui_default_colors_set ();
7023
7045
0 commit comments