@@ -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,
@@ -5831,18 +5840,28 @@ int screen_valid(int doclear)
5831
5840
/// (re)allocate a window grid if size changed
5832
5841
/// If "doclear" is true, clear the screen if resized.
5833
5842
// TODO(utkarshme): Think of a better name, place
5834
- void window_grid_alloc (win_T * wp , int doclear )
5843
+ void win_grid_alloc (win_T * wp , int doclear )
5835
5844
{
5836
- if (wp -> w_grid .ScreenLines != NULL
5837
- && wp -> w_grid .Rows == wp -> w_height
5838
- && wp -> w_grid .Columns == wp -> w_width ) {
5839
- return ;
5840
- }
5845
+ if (wp -> w_grid .ScreenLines == NULL
5846
+ || wp -> w_grid .Rows != wp -> w_height
5847
+ || wp -> w_grid .Columns != wp -> w_width ) {
5848
+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5849
+
5850
+ // only assign a grid handle if not already
5851
+ if (wp -> w_grid .handle == 0 ) {
5852
+ wp -> w_grid .handle = ++ last_handle ;
5853
+ }
5854
+
5855
+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5856
+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5841
5857
5842
- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5858
+ wp -> w_grid .was_resized = true;
5859
+ }
5843
5860
5844
- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5845
- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5861
+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5862
+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5863
+ wp -> w_grid .was_resized = false;
5864
+ }
5846
5865
}
5847
5866
5848
5867
/*
@@ -5936,6 +5955,7 @@ void screenalloc(bool doclear)
5936
5955
5937
5956
default_grid .OffsetRow = 0 ;
5938
5957
default_grid .OffsetColumn = 0 ;
5958
+ default_grid .handle = 1 ;
5939
5959
5940
5960
must_redraw = CLEAR ; /* need to clear the screen later */
5941
5961
if (doclear )
@@ -5960,7 +5980,7 @@ void screenalloc(bool doclear)
5960
5980
void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
5961
5981
{
5962
5982
int new_row , old_row ;
5963
- ScreenGrid new = { 0 } ;
5983
+ ScreenGrid new = * grid ;
5964
5984
5965
5985
size_t ncells = (size_t )((rows + 1 ) * columns );
5966
5986
new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6247,7 +6267,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
6247
6267
}
6248
6268
}
6249
6269
6250
- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6270
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
6251
6271
6252
6272
return OK ;
6253
6273
}
@@ -6299,7 +6319,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
6299
6319
}
6300
6320
}
6301
6321
6302
- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6322
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
6303
6323
6304
6324
return OK ;
6305
6325
}
@@ -7052,6 +7072,8 @@ void screen_resize(int width, int height)
7052
7072
default_grid .Rows = screen_Rows ;
7053
7073
default_grid .Columns = screen_Columns ;
7054
7074
7075
+ send_grid_resize = true;
7076
+
7055
7077
/* The window layout used to be adjusted here, but it now happens in
7056
7078
* screenalloc() (also invoked from screenclear()). That is because the
7057
7079
* "busy" check above may skip this, but not screenalloc(). */
0 commit comments