@@ -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 , true); // any popup menu will be redrawn below
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;
@@ -2240,7 +2249,7 @@ win_line (
2240
2249
row = startrow ;
2241
2250
2242
2251
// allocate window grid if not already
2243
- window_grid_alloc (wp , true);
2252
+ win_grid_alloc (wp , true);
2244
2253
2245
2254
/*
2246
2255
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5844,18 +5853,28 @@ int screen_valid(int doclear)
5844
5853
/// (re)allocate a window grid if size changed
5845
5854
/// If "doclear" is true, clear the screen if resized.
5846
5855
// TODO(utkarshme): Think of a better name, place
5847
- void window_grid_alloc (win_T * wp , int doclear )
5856
+ void win_grid_alloc (win_T * wp , int doclear )
5848
5857
{
5849
- if (wp -> w_grid .ScreenLines != NULL
5850
- && wp -> w_grid .Rows == wp -> w_height
5851
- && wp -> w_grid .Columns == wp -> w_width ) {
5852
- return ;
5853
- }
5858
+ if (wp -> w_grid .ScreenLines == NULL
5859
+ || wp -> w_grid .Rows != wp -> w_height
5860
+ || wp -> w_grid .Columns != wp -> w_width ) {
5861
+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5862
+
5863
+ // only assign a grid handle if not already
5864
+ if (wp -> w_grid .handle == 0 ) {
5865
+ wp -> w_grid .handle = ++ last_handle ;
5866
+ }
5867
+
5868
+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5869
+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5854
5870
5855
- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5871
+ wp -> w_grid .was_resized = true;
5872
+ }
5856
5873
5857
- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5858
- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5874
+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5875
+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5876
+ wp -> w_grid .was_resized = false;
5877
+ }
5859
5878
}
5860
5879
5861
5880
/*
@@ -5949,6 +5968,7 @@ void screenalloc(bool doclear)
5949
5968
5950
5969
default_grid .OffsetRow = 0 ;
5951
5970
default_grid .OffsetColumn = 0 ;
5971
+ default_grid .handle = 1 ;
5952
5972
5953
5973
must_redraw = CLEAR ; /* need to clear the screen later */
5954
5974
if (doclear )
@@ -5973,7 +5993,7 @@ void screenalloc(bool doclear)
5973
5993
void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
5974
5994
{
5975
5995
int new_row , old_row ;
5976
- ScreenGrid new = { 0 } ;
5996
+ ScreenGrid new = * grid ;
5977
5997
5978
5998
size_t ncells = (size_t )((rows + 1 ) * columns );
5979
5999
new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6260,7 +6280,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
6260
6280
}
6261
6281
}
6262
6282
6263
- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6283
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
6264
6284
6265
6285
return OK ;
6266
6286
}
@@ -6312,7 +6332,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
6312
6332
}
6313
6333
}
6314
6334
6315
- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6335
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
6316
6336
6317
6337
return OK ;
6318
6338
}
@@ -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