Fix: Inconsistent Textarea resizing in small windows

6e29ad4b50fb1b99e0f3dbeab1fe68f3fa58f23a

Joe <joenunezb@gmail.com>

1 files changed, +15 -9Showing whitespace changes
public/scripts/RossAscends-mods.js+15 -9
@@ -699,20 +699,26 @@ const chatBlock = document.getElementById('chat');
699699const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
700700
701701/**
702- * this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
702+ * Auto-resizes the send message textarea to fit its content, up to a maximum height defined by CSS.
703+ * This function preserves chat scroll position, resets the textarea height for accurate measurement,
704+ * calculates the required height, sets the new height, and then restores the chat scroll position.
705+ * Firefox-specific scrolling adjustments are included for smoother behavior.
703706 */
704707function autoFitSendTextArea() {
705708 const originalScrollBottomoriginalScrollTop = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight);
706- if (Math.ceil(sendTextArea.scrollHeight + 3) >= Math.floor(sendTextArea.offsetHeight)) {
709+ const originalScrollHeight = chatBlock.scrollHeight;
707- const sendTextAreaMinHeight = '0px';
710+
708711 sendTextArea.style.height = sendTextAreaMinHeight'1px';
709- }
712+
710713 const newHeight = sendTextArea.scrollHeight + 3;
714+
711715 sendTextArea.style.height = `${newHeight}px`;
712716
717+ // Restore chat scroll position (Firefox-specific adjustment for smoothness).
713718 if (!isFirefox) {
714719 const newScrollTopchatBlock.scrollTop = Math.round(chatBlock.scrollHeightoriginalScrollTop -+ (chatBlock.offsetHeightscrollHeight +- originalScrollBottom)originalScrollHeight);
715- chatBlock.scrollTop = newScrollTop;
720+ } else {
721+ chatBlock.scrollTo({ top: chatBlock.scrollHeight, behavior: 'auto' });
716722 }
717723}
718724export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);