From f3bc39fa05011debc52f6f4c1009fdd4e19bffba Mon Sep 17 00:00:00 2001 From: Alan Davies Date: Tue, 26 Nov 2024 21:55:17 +0000 Subject: [PATCH] Override the ChatLog.scrollBottom() function to skip over hidden messages. --- scripts/damage-log.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/damage-log.js b/scripts/damage-log.js index e3205ac..3043351 100644 --- a/scripts/damage-log.js +++ b/scripts/damage-log.js @@ -239,6 +239,7 @@ class DamageLog { if (game.modules.get('lib-wrapper')?.active) { libWrapper.register('damage-log', 'ChatLog.prototype.notify', this.#onChatLogNotify, 'MIXED'); + libWrapper.register('damage-log', 'ChatLog.prototype.scrollBottom', this.#onScrollBottom, 'OVERRIDE'); if (!this.hasCustomizableChatTabs) { libWrapper.register('damage-log', 'Messages.prototype.flush', this.#onMessageLogFlush.bind(this), 'MIXED'); @@ -413,6 +414,22 @@ class DamageLog { return wrapper(message, ...args); } + /** + * Override the ChatLog.scrollBottom() function to skip over hidden messages. + */ + async #onScrollBottom({popout=false, waitImages=false, scrollOptions={}}={}) { + if ( !this.rendered ) return; + if ( waitImages ) await this._waitForImages(); + const log = this.element[0].querySelector("#chat-log"); + let child = log.lastElementChild; + // Skip backwards over any hidden chat items + while ((child != null) && (window.getComputedStyle(child).display === "none")) { + child = child.previousElementSibling; + } + child?.scrollIntoView(scrollOptions); + if ( popout ) this._popout?.scrollBottom({waitImages, scrollOptions}); + } + /** * Handle updating the timestamps on damage log messages. */