| 699 | const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; | 699 | const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; |
| 700 | | 700 | |
| 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 | */ |
| 707 | function autoFitSendTextArea() { | 705 | function 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'; | | |
| 712 | | | |
| 713 | const newHeight = sendTextArea.scrollHeight; | | |
| 714 | | 707 | |
| | 708 | sendTextArea.style.height = '1px'; // Reset height to 1px to force recalculation of scrollHeight |
| | 709 | const newHeight = sendTextArea.scrollHeight; |
| 715 | sendTextArea.style.height = `${newHeight}px`; | 710 | sendTextArea.style.height = `${newHeight}px`; |
| 716 | | 711 | |
| 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 | } |
| 724 | export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short); | 716 | export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short); |