Fix: Inconsistent Textarea resizing in small windows

9d77140ea589e08d86c2d135ae4556f6eb9830fb

Joe <joenunezb@gmail.com>

1 files changed, +15 -9Showing whitespace changes
public/scripts/RossAscends-mods.js+15 -9
@@ -697,20 +697,26 @@ const chatBlock = document.getElementById('chat');
697const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;697const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
698698
699/**699/**
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.
701 */704 */
702function autoFitSendTextArea() {705function autoFitSendTextArea() {
703 const originalScrollBottom = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight);706 const originalScrollTop = chatBlock.scrollTop;
704 if (Math.ceil(sendTextArea.scrollHeight + 3) >= Math.floor(sendTextArea.offsetHeight)) {707 const originalScrollHeight = chatBlock.scrollHeight;
705 const sendTextAreaMinHeight = '0px';708
706 sendTextArea.style.height = sendTextAreaMinHeight;709 sendTextArea.style.height = '1px';
707 }710
708 const newHeight = sendTextArea.scrollHeight + 3;711 const newHeight = sendTextArea.scrollHeight;
712
709 sendTextArea.style.height = `${newHeight}px`;713 sendTextArea.style.height = `${newHeight}px`;
710714
715 // Restore chat scroll position (Firefox-specific adjustment for smoothness).
711 if (!isFirefox) {716 if (!isFirefox) {
712 const newScrollTop = Math.round(chatBlock.scrollHeight - (chatBlock.offsetHeight + originalScrollBottom));717 chatBlock.scrollTop = originalScrollTop + (chatBlock.scrollHeight - originalScrollHeight);
713 chatBlock.scrollTop = newScrollTop;718 } else {
719 chatBlock.scrollTo({ top: chatBlock.scrollHeight, behavior: 'auto' });
714 }720 }
715}721}
716export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);722export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);