| 697 | 697 | const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; |
| 698 | 698 | |
| 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 | */ |
| 702 | 705 | function autoFitSendTextArea() { |
| 703 | 706 | 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 | + |
| 706 | 709 | sendTextArea.style.height = sendTextAreaMinHeight'1px'; |
| 707 | | - } |
| 710 | + |
| 708 | 711 | const newHeight = sendTextArea.scrollHeight + 3; |
| 712 | + |
| 709 | 713 | sendTextArea.style.height = `${newHeight}px`; |
| 710 | 714 | |
| 715 | + // Restore chat scroll position (Firefox-specific adjustment for smoothness). |
| 711 | 716 | if (!isFirefox) { |
| 712 | 717 | 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' }); |
| 714 | 720 | } |
| 715 | 721 | } |
| 716 | 722 | export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short); |