@@ -39,6 +39,25 @@ export class IrisGridMetricCalculator extends GridMetricCalculator {
39
39
( columns : readonly dh . Column [ ] ) => columns . map ( col => col . name )
40
40
) ;
41
41
42
+ private updateCalculatedColumnWidths ( model : IrisGridModel ) : void {
43
+ assertNotNull ( this . cachedModelColumnNames ) ;
44
+ const calculatedColumnWidthsByName = new Map < ColumnName , number > ( ) ;
45
+ this . cachedModelColumnNames . forEach ( ( name , index ) => {
46
+ const prevColumnWidth = this . calculatedColumnWidths . get ( index ) ;
47
+ if ( prevColumnWidth != null ) {
48
+ calculatedColumnWidthsByName . set ( name , prevColumnWidth ) ;
49
+ }
50
+ } ) ;
51
+ this . resetCalculatedColumnWidths ( ) ;
52
+ calculatedColumnWidthsByName . forEach ( ( width , name ) => {
53
+ const index = model . getColumnIndexByName ( name ) ;
54
+ if ( index != null ) {
55
+ this . calculatedColumnWidths . set ( index , width ) ;
56
+ }
57
+ } ) ;
58
+ trimMap ( this . calculatedColumnWidths ) ;
59
+ }
60
+
42
61
/**
43
62
* Updates the user column widths based on the current model state
44
63
* @param model The current IrisGridModel
@@ -61,14 +80,17 @@ export class IrisGridMetricCalculator extends GridMetricCalculator {
61
80
// Comparing model.columns references wouldn't work here because
62
81
// the reference can change in the model without the actual column definitions changing
63
82
if (
83
+ this . cachedModelColumnNames != null &&
64
84
! deepEqual (
65
85
this . getCachedCurrentModelColumnNames ( model . columns ) ,
66
86
this . cachedModelColumnNames
67
87
)
68
88
) {
69
- this . resetCalculatedColumnWidths ( ) ;
89
+ // Preserve column widths when possible to minimize visual shifts in the grid layout
90
+ this . updateCalculatedColumnWidths ( model ) ;
70
91
this . updateUserColumnWidths ( model ) ;
71
92
}
93
+ this . cachedModelColumnNames = model . columns . map ( col => col . name ) ;
72
94
}
73
95
74
96
getGridY ( state : IrisGridMetricState ) : number {
@@ -108,7 +130,6 @@ export class IrisGridMetricCalculator extends GridMetricCalculator {
108
130
// Update column widths if columns in the cached model don't match the current model passed in the state
109
131
this . updateColumnWidthsIfNecessary ( model ) ;
110
132
111
- this . cachedModelColumnNames = model . columns . map ( col => col . name ) ;
112
133
return super . getMetrics ( state ) ;
113
134
}
114
135
0 commit comments