| 699 | const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; | 699 | const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; |
| 700 | | 700 | |
| 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 | */ |
| 704 | function autoFitSendTextArea() { | 707 | function 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`; |
| 712 | | 716 | |
| | 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 | } |
| 718 | export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short); | 724 | export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short); |