From 46408465ce3869a4e4b6975b2350a2c56788f9ff Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Thu, 17 Aug 2023 01:03:40 -0300 Subject: [PATCH] Improved chat scrolling (#3601) --- css/main.css | 8 ++++++-- js/main.js | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/css/main.css b/css/main.css index 425a531c..a97a18ca 100644 --- a/css/main.css +++ b/css/main.css @@ -253,6 +253,10 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { .bigchat #chat { height: calc(100dvh - 180px) !important; } + + .chat { + flex-direction: column-reverse !important; + } } .chat { @@ -263,10 +267,10 @@ div.svelte-362y77>*, div.svelte-362y77>.form>* { overflow-y: auto; padding-right: 20px; display: flex; - flex-direction: column-reverse; + flex-direction: column; word-break: break-word; overflow-wrap: anywhere; - padding-top: 1px; + padding-top: 6px; } #chat { diff --git a/js/main.js b/js/main.js index 40197869..68a511fc 100644 --- a/js/main.js +++ b/js/main.js @@ -48,3 +48,26 @@ document.addEventListener("keydown", function(event) { } } }); + +// Chat scrolling +const targetElement = document.getElementById('chat').parentNode.parentNode.parentNode; + +// Create a MutationObserver instance +const observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + let childElement = targetElement.childNodes[2].childNodes[0].childNodes[1]; + childElement.scrollTop = childElement.scrollHeight; + }); +}); + +// Configure the observer to watch for changes in the subtree and attributes +const config = { + childList: true, + subtree: true, + characterData: true, + attributeOldValue: true, + characterDataOldValue: true +}; + +// Start observing the target element +observer.observe(targetElement, config);