@@ -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
@@ -421,6 +429,7 @@ void update_screen(int type)
421
429
win_redr_status (wp );
422
430
}
423
431
}
432
+ send_grid_resize = false;
424
433
end_search_hl ();
425
434
// May need to redraw the popup menu.
426
435
if (pum_drawn ()) {
@@ -653,7 +662,7 @@ static void win_update(win_T *wp)
653
662
654
663
type = wp -> w_redr_type ;
655
664
656
- window_grid_alloc (wp , false);
665
+ win_grid_alloc (wp , false);
657
666
658
667
if (type == NOT_VALID ) {
659
668
wp -> w_redr_status = TRUE;
@@ -2219,7 +2228,7 @@ win_line (
2219
2228
row = startrow ;
2220
2229
2221
2230
// allocate window grid if not already
2222
- window_grid_alloc (wp , true);
2231
+ win_grid_alloc (wp , true);
2223
2232
2224
2233
/*
2225
2234
* To speed up the loop below, set extra_check when there is linebreak,
@@ -5808,18 +5817,28 @@ int screen_valid(int doclear)
5808
5817
/// (re)allocate a window grid if size changed
5809
5818
/// If "doclear" is true, clear the screen if resized.
5810
5819
// TODO(utkarshme): Think of a better name, place
5811
- void window_grid_alloc (win_T * wp , int doclear )
5820
+ void win_grid_alloc (win_T * wp , int doclear )
5812
5821
{
5813
- if (wp -> w_grid .ScreenLines != NULL
5814
- && wp -> w_grid .Rows == wp -> w_height
5815
- && wp -> w_grid .Columns == wp -> w_width ) {
5816
- return ;
5817
- }
5822
+ if (wp -> w_grid .ScreenLines == NULL
5823
+ || wp -> w_grid .Rows != wp -> w_height
5824
+ || wp -> w_grid .Columns != wp -> w_width ) {
5825
+ grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5826
+
5827
+ // only assign a grid handle if not already
5828
+ if (wp -> w_grid .handle == 0 ) {
5829
+ wp -> w_grid .handle = ++ last_handle ;
5830
+ }
5831
+
5832
+ wp -> w_grid .OffsetRow = wp -> w_winrow ;
5833
+ wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5818
5834
5819
- grid_alloc (& wp -> w_grid , wp -> w_height , wp -> w_width , doclear );
5835
+ wp -> w_grid .was_resized = true;
5836
+ }
5820
5837
5821
- wp -> w_grid .OffsetRow = wp -> w_winrow ;
5822
- wp -> w_grid .OffsetColumn = wp -> w_wincol ;
5838
+ if (send_grid_resize || wp -> w_grid .was_resized ) {
5839
+ ui_call_grid_resize (wp -> w_grid .handle , wp -> w_grid .Columns , wp -> w_grid .Rows );
5840
+ wp -> w_grid .was_resized = false;
5841
+ }
5823
5842
}
5824
5843
5825
5844
/*
@@ -5913,6 +5932,7 @@ void screenalloc(bool doclear)
5913
5932
5914
5933
default_grid .OffsetRow = 0 ;
5915
5934
default_grid .OffsetColumn = 0 ;
5935
+ default_grid .handle = 1 ;
5916
5936
5917
5937
must_redraw = CLEAR ; /* need to clear the screen later */
5918
5938
if (doclear )
@@ -5937,7 +5957,7 @@ void screenalloc(bool doclear)
5937
5957
void grid_alloc (ScreenGrid * grid , int rows , int columns , bool copy )
5938
5958
{
5939
5959
int new_row , old_row ;
5940
- ScreenGrid new = { 0 } ;
5960
+ ScreenGrid new = * grid ;
5941
5961
5942
5962
size_t ncells = (size_t )((rows + 1 ) * columns );
5943
5963
new .ScreenLines = xmalloc (ncells * sizeof (schar_T ));
@@ -6224,7 +6244,7 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end,
6224
6244
}
6225
6245
}
6226
6246
6227
- ui_call_grid_scroll (1 , row , end , col , col + width , - line_count , 0 );
6247
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , - line_count , 0 );
6228
6248
6229
6249
return OK ;
6230
6250
}
@@ -6276,7 +6296,7 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end,
6276
6296
}
6277
6297
}
6278
6298
6279
- ui_call_grid_scroll (1 , row , end , col , col + width , line_count , 0 );
6299
+ ui_call_grid_scroll (grid -> handle , row , end , col , col + width , line_count , 0 );
6280
6300
6281
6301
return OK ;
6282
6302
}
@@ -7019,6 +7039,8 @@ void screen_resize(int width, int height)
7019
7039
default_grid .Rows = screen_Rows ;
7020
7040
default_grid .Columns = screen_Columns ;
7021
7041
7042
+ send_grid_resize = true;
7043
+
7022
7044
// TODO(bfredl): update default colors when they changed, NOT on resize.
7023
7045
ui_default_colors_set ();
7024
7046
0 commit comments