Skip to content

Commit 01c2a06

Browse files
authored
fix: Fix issues when auto-size columns/rows is false, and when row headers are not 0 (deephaven#1927)
- Shouldn't throw in those cases, we should handle when calculatedSizes is empty - Found when using out [deephaven-doom](https://github.com/mofojed/deephaven-doom), couldn't resize/move columns like expected - Also tested in the styleguide - dragging columns when there were row headers visible did not work correctly
1 parent 7af32cc commit 01c2a06

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

packages/grid/src/GridRenderer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,9 @@ export class GridRenderer {
23232323
);
23242324
context.clip();
23252325

2326-
context.translate(draggingLeft - originalLeft, 0);
2326+
// The header drawing functions expect the context to be at the edge of the canvas
2327+
// We offset it by how much the user has dragged
2328+
context.translate(draggingLeft - originalLeft - gridX, 0);
23272329
context.font = headerFont;
23282330

23292331
const visibleColumns: VisibleIndex[] = [];
@@ -2352,11 +2354,14 @@ export class GridRenderer {
23522354
}
23532355
);
23542356

2355-
context.translate(0, gridY);
2357+
// Now move to the edge of the "grid" (top-left of top-left cell). We then draw the
2358+
// grid background, but only the clipped region will be drawn where the dragging column is.
2359+
context.translate(gridX, gridY);
23562360
context.font = font;
23572361

23582362
this.drawGridBackground(context, state);
23592363

2364+
// Then draw the contents of the column that is being dragged
23602365
for (let i = startIndex; i <= endIndex; i += 1) {
23612366
this.drawColumnCellContents(context, state, i);
23622367
}

packages/grid/src/mouse-handlers/GridColumnMoveMouseHandler.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import clamp from 'lodash.clamp';
2+
import { assertNotNull } from '@deephaven/utils';
23
import Grid from '../Grid';
34
import GridUtils, { GridPoint } from '../GridUtils';
45
import GridMouseHandler, { GridMouseEvent } from '../GridMouseHandler';
@@ -381,6 +382,9 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
381382
) {
382383
return;
383384
}
385+
const { metrics } = grid;
386+
assertNotNull(metrics, 'Metrics not set');
387+
const { gridX } = metrics;
384388

385389
// Cursor has moved past the column drag bounds, don't move the column until we hit the initial offset point again
386390
if (this.initialOffset !== this.draggingOffset) {
@@ -400,7 +404,7 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
400404

401405
this.draggingColumn = {
402406
...this.draggingColumn,
403-
left: mouseX - this.draggingOffset,
407+
left: mouseX - this.draggingOffset - gridX,
404408
};
405409
grid.setState({ draggingColumn: this.draggingColumn });
406410
return;
@@ -410,8 +414,6 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
410414

411415
const { model } = grid.props;
412416
const { movedColumns } = grid.state;
413-
const { metrics } = grid;
414-
if (!metrics) throw new Error('Metrics not set');
415417

416418
const { floatingLeftWidth, width, columnHeaderMaxDepth, allColumnXs } =
417419
metrics;
@@ -431,7 +433,7 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
431433

432434
// The returned left/right are the original position, not dragged position
433435
// This is where the dragging column's floating position accounting for dragged distance
434-
const floatingDraggingLeft = mouseX - this.draggingOffset;
436+
const floatingDraggingLeft = mouseX - this.draggingOffset - gridX;
435437
const floatingDraggingRight = floatingDraggingLeft + draggingColumn.width;
436438

437439
this.draggingColumn = {
@@ -448,7 +450,7 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
448450
isDraggingLeft ? floatingDraggingLeft : floatingDraggingRight,
449451
floatingLeftWidth,
450452
width
451-
),
453+
) + gridX,
452454
metrics,
453455
true
454456
),
@@ -481,7 +483,7 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
481483
mouseX - (allColumnXs.get(parentVisibleRange[0]) ?? 0);
482484
this.draggingColumn = {
483485
...this.draggingColumn,
484-
left: mouseX - this.draggingOffset,
486+
left: mouseX - this.draggingOffset - gridX,
485487
};
486488
this.clearScrollInterval();
487489
grid.setState({
@@ -506,7 +508,7 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
506508
this.draggingOffset = mouseX - (parentRight - draggingColumn.width);
507509
this.draggingColumn = {
508510
...this.draggingColumn,
509-
left: mouseX - this.draggingOffset,
511+
left: mouseX - this.draggingOffset - gridX,
510512
};
511513
this.clearScrollInterval();
512514
grid.setState({
@@ -570,7 +572,7 @@ class GridColumnMoveMouseHandler extends GridMouseHandler {
570572

571573
this.draggingColumn = {
572574
...this.draggingColumn,
573-
left: mouseX - this.draggingOffset,
575+
left: mouseX - this.draggingOffset - gridX,
574576
};
575577

576578
grid.setState({

packages/grid/src/mouse-handlers/GridSeparatorMouseHandler.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ abstract class GridSeparatorMouseHandler extends GridMouseHandler {
174174
const targetSize = this.targetSizes.get(modelIndex);
175175
const isResizingMultiple = this.resizingItems.length > 1;
176176
const hiddenIndex = this.hiddenItems.indexOf(resizeIndex);
177-
let calculatedSize = getOrThrow(calculatedSizes, modelIndex);
178-
if (resizeIndex === firstIndex) {
177+
let calculatedSize = calculatedSizes.get(modelIndex);
178+
if (calculatedSize != null && resizeIndex === firstIndex) {
179179
calculatedSize += treePadding;
180180
}
181181
let newSize = itemSize;
182182
if (
183+
calculatedSize != null &&
183184
Math.abs(itemSize - calculatedSize) <= theme.headerResizeSnapThreshold
184185
) {
185186
// Snapping behaviour to "natural" width
@@ -275,14 +276,12 @@ abstract class GridSeparatorMouseHandler extends GridMouseHandler {
275276
const modelIndexes = metrics[this.modelIndexesProperty];
276277
const modelIndex = getOrThrow(modelIndexes, separator.index);
277278

278-
const calculatedSize = getOrThrow(
279-
metrics[this.calculatedSizesProperty],
280-
modelIndex
281-
);
279+
const calculatedSize =
280+
metrics[this.calculatedSizesProperty].get(modelIndex);
282281
const defaultSize =
283282
metricCalculator[this.initialSizesProperty].get(modelIndex);
284283

285-
if (calculatedSize === defaultSize) {
284+
if (calculatedSize === defaultSize || calculatedSize == null) {
286285
this.resetSize(metricCalculator, modelIndex);
287286
} else {
288287
this.setSize(metricCalculator, modelIndex, calculatedSize);
@@ -314,7 +313,7 @@ abstract class GridSeparatorMouseHandler extends GridMouseHandler {
314313
const modelIndex = getOrThrow(modelIndexes, itemIndex);
315314
let targetSize = userSizes.get(modelIndex);
316315
if (targetSize == null || targetSize === 0) {
317-
targetSize = getOrThrow(calculatedSizes, modelIndex) + treePadding;
316+
targetSize = (calculatedSizes.get(modelIndex) ?? 0) + treePadding;
318317
}
319318
this.targetSizes.set(modelIndex, targetSize);
320319
}

0 commit comments

Comments
 (0)