(core) Fixing scrolling for linked sections

Summary:
When a grid is scrolled, and then data is changed (due to click in a linked section), some
records are not rendered, or position of the scroll container is corrupted

Test Plan: Added

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3661
This commit is contained in:
Jarosław Sadziński 2022-11-09 16:03:26 +01:00
parent 42c3568835
commit 2248053b09
2 changed files with 13 additions and 11 deletions

View File

@ -297,8 +297,7 @@ Scrolly.prototype.updateSize = function() {
this.numRendered = numVisible + 2 * this.numBuffered;
// Re-render everything.
this.begin = gutil.clamp(this.begin, 0, this.numRows - this.numRendered);
this.end = gutil.clamp(this.begin + this.numRendered, 0, this.numRows);
this._updateRange();
this.render();
this.syncScrollPosition();
};
@ -333,10 +332,7 @@ Scrolly.prototype.scrollTo = function(top) {
// just particularly easy to come across.
var atEnd = (top + this.shownHeight >= this.panes[0].container.scrollHeight);
var rowAtScrollTop = this.rowOffsetTree.getIndex(top);
this.begin = gutil.clamp(rowAtScrollTop - this.numBuffered, 0, this.numRows - this.numRendered);
this.end = gutil.clamp(this.begin + this.numRendered, 0, this.numRows);
this._updateRange();
// Do the magic.
this.render();
@ -367,11 +363,7 @@ Scrolly.prototype.onDataSplice = function(splice) {
this.rowOffsetTree.fillFromValues(this.rowHeights);
this.totalHeight(this.rowOffsetTree.getTotal() + this.options.paddingBottom);
// We may be seeing the last row with space below it, so we'll use the same logic as in
// scrollTo, to make sure the rendered range includes all rows we should be seeing.
var rowAtScrollTop = this.rowOffsetTree.getIndex(this.scrollTop);
this.begin = gutil.clamp(rowAtScrollTop - this.numBuffered, 0, this.numRows - this.numRendered);
this.end = gutil.clamp(this.begin + this.numRendered, 0, this.numRows);
this._updateRange();
this.scheduleUpdateSize();
};
@ -617,6 +609,16 @@ Scrolly.prototype.destroyPane = function(pane) {
}
};
/**
* Updates indexes of rows to render.
*/
Scrolly.prototype._updateRange = function() {
// If we are scrolled from the top, start at the first visible row with some buffer.
const begin = this.rowOffsetTree.getIndex(this.scrollTop) - this.numBuffered;
this.begin = gutil.clamp(begin, 0, this.numRows - this.numRendered);
this.end = gutil.clamp(this.begin + this.numRendered, 0, this.numRows);
}
//----------------------------------------------------------------------
/**

BIN
test/fixtures/docs/Teams.grist vendored Normal file

Binary file not shown.