@@ -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 ()) {
@@ -654,7 +663,7 @@ static void win_update(win_T *wp)
654
663
655
664
type = wp -> w_redr_type ;
656
665
657
- window_grid_alloc (wp , false);
666
+ win_grid_alloc (wp , false);
658
667
659
668
if (type == NOT_VALID ) {
660
669
wp -> w_redr_status = TRUE;
@@ -2221,7 +2230,7 @@ win_line (
2221
2230
row = startrow ;
2222
2231
2223
2232
// allocate window grid if not already
2224
- window_grid_alloc (wp , true);
2233
+ win_grid_alloc (wp , true);
2225
2234
2226
2235
/*
2227
2236
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5821,18 +5830,28 @@ int screen_valid(int doclear)
5821
5830
/// (re)allocate a window grid if size changed
5822
5831
/// If "doclear" is true, clear the screen if resized.
5823
5832
// TODO(utkarshme): Think of a better name, place
5824
- void window_grid_alloc (win_T * wp , int doclear )
5833
+ void win_grid_alloc (win_T * wp , int doclear )
5825
5834
{
5826
- if (wp -> w_grid .ScreenLines != NULL
5827
- && wp -> w_grid .Rows == wp -> w_height
5828
- && wp -> w_grid .Columns == wp -> w_width ) {
5829
- return ;
5830
- }
5835
+ if (wp -> w_grid .ScreenLines == NULL
5836
+ || wp -> w_grid .Rows != wp -> w_height
5837
+ || wp -> w_grid .Columns != wp -> w_width ) {
5838
+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5839
+
5840
+ // only assign a grid handle if not already
5841
+ if (wp -> w_grid .handle == 0 ) {
5842
+ wp -> w_grid .handle = ++ last_handle ;
5843
+ }
5844
+
5845
+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5846
+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5831
5847
5832
- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5848
+ wp -> w_grid .was_resized = true;
5849
+ }
5833
5850
5834
- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5835
- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5851
+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5852
+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5853
+ wp -> w_grid .was_resized = false;
5854
+ }
5836
5855
}
5837
5856
5838
5857
/*
@@ -5926,6 +5945,7 @@ void screenalloc(bool doclear)
5926
5945
5927
5946
default_grid .OffsetRow = 0 ;
5928
5947
default_grid .OffsetColumn = 0 ;
5948
+ default_grid .handle = 1 ;
5929
5949
5930
5950
must_redraw = CLEAR ; /* need to clear the screen later */
5931
5951
if (doclear )
@@ -5950,7 +5970,7 @@ void screenalloc(bool doclear)
5950
5970
void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
5951
5971
{
5952
5972
int new_row , old_row ;
5953
- ScreenGrid new = { 0 } ;
5973
+ ScreenGrid new = * grid ;
5954
5974
5955
5975
size_t ncells = (size_t )((rows + 1 ) * columns );
5956
5976
new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6237,7 +6257,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
6237
6257
}
6238
6258
}
6239
6259
6240
- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6260
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
6241
6261
6242
6262
return OK ;
6243
6263
}
@@ -6289,7 +6309,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
6289
6309
}
6290
6310
}
6291
6311
6292
- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6312
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
6293
6313
6294
6314
return OK ;
6295
6315
}
@@ -7032,6 +7052,8 @@ void screen_resize(int width, int height)
7032
7052
default_grid .Rows = screen_Rows ;
7033
7053
default_grid .Columns = screen_Columns ;
7034
7054
7055
+ send_grid_resize = true;
7056
+
7035
7057
/* The window layout used to be adjusted here, but it now happens in
7036
7058
* screenalloc() (also invoked from screenclear()). That is because the
7037
7059
* "busy" check above may skip this, but not screenalloc(). */
0 commit comments