Skip to content

Commit

Permalink
Override the ChatLog.scrollBottom() function to skip over hidden mess…
Browse files Browse the repository at this point in the history
…ages.
  • Loading branch information
cs96and committed Nov 26, 2024
1 parent 8978058 commit f3bc39f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scripts/damage-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit f3bc39f

Please sign in to comment.