(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; this.numRendered = numVisible + 2 * this.numBuffered;
// Re-render everything. // Re-render everything.
this.begin = gutil.clamp(this.begin, 0, this.numRows - this.numRendered); this._updateRange();
this.end = gutil.clamp(this.begin + this.numRendered, 0, this.numRows);
this.render(); this.render();
this.syncScrollPosition(); this.syncScrollPosition();
}; };
@ -333,10 +332,7 @@ Scrolly.prototype.scrollTo = function(top) {
// just particularly easy to come across. // just particularly easy to come across.
var atEnd = (top + this.shownHeight >= this.panes[0].container.scrollHeight); var atEnd = (top + this.shownHeight >= this.panes[0].container.scrollHeight);
var rowAtScrollTop = this.rowOffsetTree.getIndex(top); this._updateRange();
this.begin = gutil.clamp(rowAtScrollTop - this.numBuffered, 0, this.numRows - this.numRendered);
this.end = gutil.clamp(this.begin + this.numRendered, 0, this.numRows);
// Do the magic. // Do the magic.
this.render(); this.render();
@ -367,11 +363,7 @@ Scrolly.prototype.onDataSplice = function(splice) {
this.rowOffsetTree.fillFromValues(this.rowHeights); this.rowOffsetTree.fillFromValues(this.rowHeights);
this.totalHeight(this.rowOffsetTree.getTotal() + this.options.paddingBottom); 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 this._updateRange();
// 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.scheduleUpdateSize(); 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.