-
Notifications
You must be signed in to change notification settings - Fork 875
fix vdom scroll #4796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix vdom scroll #4796
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -334,6 +334,16 @@ export default class RowManager extends CoreFeature{ | |
| data.reverse(); | ||
| } | ||
|
|
||
| // Store initial state for large batch additions (issue #4730) | ||
| var initialScrollInfo; | ||
| if(data.length >= 100 && this.renderer && this.renderer.elementVertical){ | ||
| initialScrollInfo = { | ||
| scrollTop: this.renderer.elementVertical.scrollTop, | ||
| scrollHeight: this.renderer.elementVertical.scrollHeight, | ||
| clientHeight: this.renderer.elementVertical.clientHeight | ||
| }; | ||
| } | ||
|
|
||
| data.forEach((item, i) => { | ||
| var row = this.addRow(item, pos, index, true); | ||
| rows.push(row); | ||
|
|
@@ -344,6 +354,32 @@ export default class RowManager extends CoreFeature{ | |
|
|
||
| this.regenerateRowPositions(); | ||
|
|
||
| // Preserve relative scroll position for large batch additions (issue #4730) | ||
| if(initialScrollInfo && !pos && data.length >= 100){ | ||
|
||
| var newScrollHeight = this.renderer.elementVertical.scrollHeight; | ||
| var newClientHeight = this.renderer.elementVertical.clientHeight; | ||
|
|
||
| if(newScrollHeight > initialScrollInfo.scrollHeight){ | ||
| var initialMaxScroll = Math.max(initialScrollInfo.scrollHeight - initialScrollInfo.clientHeight, 0); | ||
| var newMaxScroll = Math.max(newScrollHeight - newClientHeight, 0); | ||
|
|
||
| if(initialMaxScroll > 0 && newMaxScroll > 0){ | ||
| // Don't use relative positioning if we were at the exact bottom | ||
| // This prevents the scrollbar from appearing to be at the bottom when more content exists | ||
| if(Math.abs(initialScrollInfo.scrollTop - initialMaxScroll) < 2){ | ||
|
||
| // We were at the bottom, but don't stick exactly to new bottom | ||
| // Leave some space to indicate there's more content | ||
| this.renderer.elementVertical.scrollTop = Math.max(0, newMaxScroll - 50); | ||
|
||
| } else { | ||
| // Use relative positioning for middle positions | ||
| var relativePosition = initialScrollInfo.scrollTop / initialMaxScroll; | ||
| var newScrollTop = relativePosition * newMaxScroll; | ||
| this.renderer.elementVertical.scrollTop = newScrollTop; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if(this.displayRowsCount){ | ||
| this._clearPlaceholder(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 100 should be extracted to a named constant or configuration option to make the threshold for scroll position preservation configurable and more maintainable.