@@ -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
@@ -422,6 +430,7 @@ void update_screen(int type)
422
430
win_redr_status (wp );
423
431
}
424
432
}
433
+ send_grid_resize = false;
425
434
end_search_hl ();
426
435
// May need to redraw the popup menu.
427
436
if (pum_drawn ()) {
@@ -661,7 +670,7 @@ static void win_update(win_T *wp)
661
670
662
671
type = wp -> w_redr_type ;
663
672
664
- window_grid_alloc (wp , false);
673
+ win_grid_alloc (wp , false);
665
674
666
675
if (type == NOT_VALID ) {
667
676
wp -> w_redr_status = TRUE;
@@ -2228,7 +2237,7 @@ win_line (
2228
2237
row = startrow ;
2229
2238
2230
2239
// allocate window grid if not already
2231
- window_grid_alloc (wp , true);
2240
+ win_grid_alloc (wp , true);
2232
2241
2233
2242
/*
2234
2243
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5838,18 +5847,28 @@ int screen_valid(int doclear)
5838
5847
/// (re)allocate a window grid if size changed
5839
5848
/// If "doclear" is true, clear the screen if resized.
5840
5849
// 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 )
5842
5851
{
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 ;
5848
5864
5849
- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5865
+ wp -> w_grid .was_resized = true;
5866
+ }
5850
5867
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
+ }
5853
5872
}
5854
5873
5855
5874
/*
@@ -5943,6 +5962,7 @@ void screenalloc(bool doclear)
5943
5962
5944
5963
default_grid .OffsetRow = 0 ;
5945
5964
default_grid .OffsetColumn = 0 ;
5965
+ default_grid .handle = 1 ;
5946
5966
5947
5967
must_redraw = CLEAR ; /* need to clear the screen later */
5948
5968
if (doclear )
@@ -5967,7 +5987,7 @@ void screenalloc(bool doclear)
5967
5987
void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
5968
5988
{
5969
5989
int new_row , old_row ;
5970
- ScreenGrid new = { 0 } ;
5990
+ ScreenGrid new = * grid ;
5971
5991
5972
5992
size_t ncells = (size_t )((rows + 1 ) * columns );
5973
5993
new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6254,7 +6274,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
6254
6274
}
6255
6275
}
6256
6276
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 );
6258
6278
6259
6279
return OK ;
6260
6280
}
@@ -6306,7 +6326,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
6306
6326
}
6307
6327
}
6308
6328
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 );
6310
6330
6311
6331
return OK ;
6312
6332
}
@@ -7059,6 +7079,8 @@ void screen_resize(int width, int height)
7059
7079
default_grid .Rows = screen_Rows ;
7060
7080
default_grid .Columns = screen_Columns ;
7061
7081
7082
+ send_grid_resize = true;
7083
+
7062
7084
/* The window layout used to be adjusted here, but it now happens in
7063
7085
* screenalloc() (also invoked from screenclear()). That is because the
7064
7086
* "busy" check above may skip this, but not screenalloc(). */
0 commit comments