From 3280fc66f55ed57bd8a690e59ba42f0169f328eb Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 25 Jun 2024 15:25:06 +0200 Subject: [PATCH] Do not trigger ScrollButton event unless clicked --- panel/layout/feed.py | 2 +- panel/models/column.ts | 15 ++++++++++++++- panel/models/feed.ts | 22 +--------------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/panel/layout/feed.py b/panel/layout/feed.py index b6ee9cf1d9..f5adf51b9a 100644 --- a/panel/layout/feed.py +++ b/panel/layout/feed.py @@ -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 diff --git a/panel/models/column.ts b/panel/models/column.ts index 6d51ce1cb1..a050e67c69 100644 --- a/panel/models/column.ts +++ b/panel/models/column.ts @@ -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 @@ -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()) }) } @@ -118,4 +127,8 @@ export class Column extends BkColumn { view_latest: [Bool, false], })) } + + on_click(callback: EventCallback): void { + this.on_event(ScrollButtonClick, callback) + } } diff --git a/panel/models/feed.ts b/panel/models/feed.ts index 6a4521fdea..c2231724f3 100644 --- a/panel/models/feed.ts +++ b/panel/models/feed.ts @@ -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 @@ -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() } } @@ -132,8 +116,4 @@ export class Feed extends Column { visible_children: [List(Str), []], })) } - - on_click(callback: EventCallback): void { - this.on_event(ScrollButtonClick, callback) - } }