Skip to content

Commit

Permalink
Ensure Feed maintains scroll position (#6984)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Jul 16, 2024
1 parent ef5d6dd commit b632f93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions panel/models/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ScrollButtonClick extends ModelEvent {

export class ColumnView extends BkColumnView {
declare model: Column
_updating: boolean = false

scroll_down_button_el: HTMLElement

Expand All @@ -30,6 +31,9 @@ export class ColumnView extends BkColumnView {
}

scroll_to_position(): void {
if (this._updating) {
return
}
requestAnimationFrame(() => {
this.el.scrollTo({top: this.model.scroll_position, behavior: "instant"})
})
Expand All @@ -56,7 +60,9 @@ export class ColumnView extends BkColumnView {
}

record_scroll_position(): void {
this._updating = true
this.model.scroll_position = Math.round(this.el.scrollTop)
this._updating = false
}

toggle_scroll_button(): void {
Expand Down
13 changes: 11 additions & 2 deletions panel/models/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {UIElementView} from "@bokehjs/models/ui/ui_element"

export class FeedView extends ColumnView {
declare model: Feed

_intersection_observer: IntersectionObserver
_last_visible: UIElementView | null
_lock: any = null
_sync: boolean

override initialize(): void {
Expand Down Expand Up @@ -54,10 +54,19 @@ export class FeedView extends ColumnView {
}

override async update_children(): Promise<void> {
const last = this._last_visible
const scroll_top = this.el.scrollTop
const before_offset = last?.el.offsetTop || 0
this._sync = false
await super.update_children()
this._sync = true
this._last_visible?.el.scrollIntoView(true)
requestAnimationFrame(() => {
const after_offset = last?.el.offsetTop || 0
const offset = (after_offset-before_offset)
if (offset > 0) {
this.el.scrollTo({top: scroll_top + offset, behavior: "instant"})
}
})
}

override async build_child_views(): Promise<UIElementView[]> {
Expand Down

0 comments on commit b632f93

Please sign in to comment.