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