Fix: Inconsistent Textarea resizing in small windows

9d77140ea589e08d86c2d135ae4556f6eb9830fb

Joe <joenunezb@gmail.com>

1 files changed, +15 -9Ignore whitespace
public/scripts/RossAscends-mods.js+15 -9
@@ -697,20 +697,26 @@ const chatBlock = document.getElementById('chat');
697697const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
698698
699699/**
700- * this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
700+ * Auto-resizes the send message textarea to fit its content, up to a maximum height defined by CSS.
701+ * This function preserves chat scroll position, resets the textarea height for accurate measurement,
702+ * calculates the required height, sets the new height, and then restores the chat scroll position.
703+ * Firefox-specific scrolling adjustments are included for smoother behavior.
701704 */
702705function autoFitSendTextArea() {
703706 const originalScrollBottomoriginalScrollTop = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight);
704- if (Math.ceil(sendTextArea.scrollHeight + 3) >= Math.floor(sendTextArea.offsetHeight)) {
707+ const originalScrollHeight = chatBlock.scrollHeight;
705- const sendTextAreaMinHeight = '0px';
708+
706709 sendTextArea.style.height = sendTextAreaMinHeight'1px';
707- }
710+
708711 const newHeight = sendTextArea.scrollHeight + 3;
712+
709713 sendTextArea.style.height = `${newHeight}px`;
710714
715+ // Restore chat scroll position (Firefox-specific adjustment for smoothness).
711716 if (!isFirefox) {
712717 const newScrollTopchatBlock.scrollTop = Math.round(chatBlock.scrollHeightoriginalScrollTop -+ (chatBlock.offsetHeightscrollHeight +- originalScrollBottom)originalScrollHeight);
713- chatBlock.scrollTop = newScrollTop;
718+ } else {
719+ chatBlock.scrollTo({ top: chatBlock.scrollHeight, behavior: 'auto' });
714720 }
715721}
716722export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);