Skip to content
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

Do not trigger ScrollButtonClick event unless clicked #6938

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion panel/layout/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _process_event(self, event: ScrollButtonClick) -> None:
n_visible = self.visible_range[-1] - self.visible_range[0]
with edit_readonly(self):
# plus one to center on the last object
self.visible_range = (max(n - n_visible + 1, 0), n)
self.visible_range = (min(max(n - n_visible + 1, 0), n), n)

with param.discard_events(self):
# reset the buffers and loaded objects
Expand Down
15 changes: 14 additions & 1 deletion panel/models/column.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import {Column as BkColumn, ColumnView as BkColumnView} from "@bokehjs/models/layouts/column"
import {ModelEvent} from "@bokehjs/core/bokeh_events"
import {div} from "@bokehjs/core/dom"
import type * as p from "@bokehjs/core/properties"
import type {EventCallback} from "@bokehjs/model"
import {Column as BkColumn, ColumnView as BkColumnView} from "@bokehjs/models/layouts/column"

export class ScrollButtonClick extends ModelEvent {
static {
this.prototype.event_name = "scroll_button_click"
}
}

export class ColumnView extends BkColumnView {
declare model: Column
Expand Down Expand Up @@ -70,6 +78,7 @@ export class ColumnView extends BkColumnView {
})
this.scroll_down_button_el.addEventListener("click", () => {
this.scroll_to_latest()
this.model.trigger_event(new ScrollButtonClick())
})
}

Expand Down Expand Up @@ -118,4 +127,8 @@ export class Column extends BkColumn {
view_latest: [Bool, false],
}))
}

on_click(callback: EventCallback<ScrollButtonClick>): void {
this.on_event(ScrollButtonClick, callback)
}
}
22 changes: 1 addition & 21 deletions panel/models/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import {Column, ColumnView} from "./column"
import type * as p from "@bokehjs/core/properties"
import {build_views} from "@bokehjs/core/build_views"
import type {UIElementView} from "@bokehjs/models/ui/ui_element"
import {ModelEvent} from "@bokehjs/core/bokeh_events"
import type {EventCallback} from "@bokehjs/model"

export class ScrollButtonClick extends ModelEvent {
static {
this.prototype.event_name = "scroll_button_click"
}
}

export class FeedView extends ColumnView {
declare model: Feed
Expand Down Expand Up @@ -89,21 +81,13 @@ export class FeedView extends ColumnView {
return created
}

override scroll_to_latest(emit_event: boolean = true): void {
if (emit_event) {
this.model.trigger_event(new ScrollButtonClick())
}
super.scroll_to_latest()
}

override trigger_auto_scroll(): void {
const limit = this.model.auto_scroll_limit
const within_limit = this.distance_from_latest <= limit
if (limit == 0 || !within_limit) {
return
}

this.scroll_to_latest(false)
this.scroll_to_latest()
}
}

Expand Down Expand Up @@ -132,8 +116,4 @@ export class Feed extends Column {
visible_children: [List(Str), []],
}))
}

on_click(callback: EventCallback<ScrollButtonClick>): void {
this.on_event(ScrollButtonClick, callback)
}
}
Loading