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');
699const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;699const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
700700
701/**701/**
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.
703 */706 */
704function autoFitSendTextArea() {707function autoFitSendTextArea() {
705 const originalScrollBottom = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight);708 const originalScrollTop = chatBlock.scrollTop;
706 if (Math.ceil(sendTextArea.scrollHeight + 3) >= Math.floor(sendTextArea.offsetHeight)) {709 const originalScrollHeight = chatBlock.scrollHeight;
707 const sendTextAreaMinHeight = '0px';710
708 sendTextArea.style.height = sendTextAreaMinHeight;711 sendTextArea.style.height = '1px';
709 }712
710 const newHeight = sendTextArea.scrollHeight + 3;713 const newHeight = sendTextArea.scrollHeight;
714
711 sendTextArea.style.height = `${newHeight}px`;715 sendTextArea.style.height = `${newHeight}px`;
712716
717 // Restore chat scroll position (Firefox-specific adjustment for smoothness).
713 if (!isFirefox) {718 if (!isFirefox) {
714 const newScrollTop = Math.round(chatBlock.scrollHeight - (chatBlock.offsetHeight + originalScrollBottom));719 chatBlock.scrollTop = originalScrollTop + (chatBlock.scrollHeight - originalScrollHeight);
715 chatBlock.scrollTop = newScrollTop;720 } else {
721 chatBlock.scrollTo({ top: chatBlock.scrollHeight, behavior: 'auto' });
716 }722 }
717}723}
718export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);724export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);