Skip to content

Commit 246d223

Browse files
committed
fix(scrolling): ensure target row/col is reached after animation
1 parent 81ae7f0 commit 246d223

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@visactor/vtable",
5+
"comment": "fix(scrolling): ensure target row/col is reached after animation",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@visactor/vtable"
10+
}

packages/vtable/src/core/BaseTable.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5126,10 +5126,10 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
51265126
getTargetScrollTop(row: number) {
51275127
const drawRange = this.getDrawRange();
51285128
const frozenHeight = this.getFrozenRowsHeight();
5129-
return Math.max(
5130-
0,
5131-
Math.min(this.getRowsHeight(0, row - 1) - frozenHeight, this.getAllRowsHeight() - drawRange.height)
5132-
);
5129+
// const rowsHeight = this.getRowsHeight(0, row - 1);
5130+
const rowsHeight = Math.ceil(this.rowHeightsMap.getSumInRange(0, row - 1)); // same as this.scrollTop
5131+
const allRowsHeight = this.getAllRowsHeight();
5132+
return Math.max(0, Math.min(rowsHeight - frozenHeight, allRowsHeight - drawRange.height));
51335133
}
51345134

51355135
private _scheduleScrollToRowCorrect(row: number, delay: number = 0) {
@@ -5192,7 +5192,10 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
51925192
// This ensures dynamically-computed row heights (e.g. autoWrapText) are reflected
51935193
// in the scroll position calculation.
51945194
const top = this.rowHeightsMap.getSumInRange(0, cellAddr.row - 1);
5195-
this.scrollTop = Math.min(top - frozenHeight, this.rowHeightsMap.getSumInRange(0, this.rowCount - 1) - drawRange.height);
5195+
this.scrollTop = Math.min(
5196+
top - frozenHeight,
5197+
this.rowHeightsMap.getSumInRange(0, this.rowCount - 1) - drawRange.height
5198+
);
51965199
}
51975200
this.render();
51985201
}

packages/vtable/src/core/animation.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ class Animateaaa extends ACustomAnimate<any> {
1212
if (this.from.x !== this.to.x) {
1313
const x = end ? this.to.x : this.from.x + Math.floor((this.to.x - this.from.x) * ratio);
1414
this.params.table.scrollLeft = x;
15+
if (ratio === 1 && this.to.targetCol !== -1) {
16+
// ensure scrollToCol is called at the end of animation to avoid not reaching the target col
17+
this.params.table.scrollToCol(this.to.targetCol, false);
18+
}
1519
}
1620
if (this.from.y !== this.to.y) {
1721
const y = end ? this.to.y : this.from.y + Math.floor((this.to.y - this.from.y) * ratio);
1822
this.params.table.scrollTop = y;
23+
if (ratio === 1 && this.to.targetRow !== -1) {
24+
// ensure scrollToRow is called at the end of animation to avoid not reaching the target row
25+
this.params.table.scrollToRow(this.to.targetRow, false);
26+
}
1927
}
2028
}
2129
}
@@ -70,7 +78,9 @@ export class TableAnimationManager {
7078

7179
const to = {
7280
x: isNumber(col) ? left - this.table.getFrozenColsWidth() : this.table.scrollLeft,
73-
y: isNumber(row) ? top - this.table.getFrozenRowsHeight() : this.table.scrollTop
81+
y: isNumber(row) ? top - this.table.getFrozenRowsHeight() : this.table.scrollTop,
82+
targetRow: rowInt ?? -1,
83+
targetCol: colInt ?? -1
7484
};
7585
const duration = !isBoolean(animationOption) ? animationOption?.duration ?? 3000 : animationOption ? 3000 : 0;
7686
const easing = !isBoolean(animationOption) ? animationOption?.easing ?? 'linear' : animationOption ? 'linear' : '';

0 commit comments

Comments
 (0)