review: Fix chrome inconsistent scroll and firefox scroll to bottom

328e3622f2340f9516723b0df9d7b23e545eb975

Joe <joenunezb@gmail.com>

1 files changed, +5 -13Showing whitespace changes
public/scripts/RossAscends-mods.js+5 -13
@@ -699,26 +699,18 @@ 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 * Auto-resizes the send message textarea to fit its content, up to a maximum height defined by CSS.702 * Resizes the chat input textarea vertically to match its text content, up to a maximum height defined in CSS.
703 * This function preserves chat scroll position, resets the textarea height for accurate measurement,703 * Preserves scroll position in Chrome. In Firefox, the textarea grows to cover the chat history.
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.
706 */704 */
707function autoFitSendTextArea() {705function autoFitSendTextArea() {
708 const originalScrollTop = chatBlock.scrollTop;706 const originalScrollBottom = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight);
709 const originalScrollHeight = chatBlock.scrollHeight;
710
711 sendTextArea.style.height = '1px';
712707
708 sendTextArea.style.height = '1px'; // Reset height to 1px to force recalculation of scrollHeight
713 const newHeight = sendTextArea.scrollHeight;709 const newHeight = sendTextArea.scrollHeight;
714
715 sendTextArea.style.height = `${newHeight}px`;710 sendTextArea.style.height = `${newHeight}px`;
716711
717 // Restore chat scroll position (Firefox-specific adjustment for smoothness).
718 if (!isFirefox) {712 if (!isFirefox) {
719 chatBlock.scrollTop = originalScrollTop + (chatBlock.scrollHeight - originalScrollHeight);713 chatBlock.scrollTop = chatBlock.scrollHeight - (chatBlock.offsetHeight + originalScrollBottom);
720 } else {
721 chatBlock.scrollTo({ top: chatBlock.scrollHeight, behavior: 'auto' });
722 }714 }
723}715}
724export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);716export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short);