| 699 | 699 | const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; |
| 700 | 700 | |
| 701 | 701 | /** |
| 702 | 702 | * Auto-resizesResizes the sendchat messageinput textarea vertically to fitmatch its text content, up to a maximum height defined byin CSS. |
| 703 | 703 | * ThisPreserves functionscroll preservesposition chatin scrollChrome. position,In resetsFirefox, the textarea heightgrows forto accuratecover measurement,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 | 705 | function autoFitSendTextArea() { |
| 708 | 706 | const originalScrollToporiginalScrollBottom = chatBlock.scrollHeight - (chatBlock.scrollTop + chatBlock.offsetHeight); |
| 709 | | - const originalScrollHeight = chatBlock.scrollHeight; |
| 710 | | - |
| 711 | | - sendTextArea.style.height = '1px'; |
| 712 | 707 | |
| 708 | + sendTextArea.style.height = '1px'; // Reset height to 1px to force recalculation of scrollHeight |
| 713 | 709 | const newHeight = sendTextArea.scrollHeight; |
| 714 | | - |
| 715 | 710 | sendTextArea.style.height = `${newHeight}px`; |
| 716 | 711 | |
| 717 | | - // Restore chat scroll position (Firefox-specific adjustment for smoothness). |
| 718 | 712 | if (!isFirefox) { |
| 719 | 713 | chatBlock.scrollTop = originalScrollTopchatBlock.scrollHeight +- (chatBlock.scrollHeightoffsetHeight -+ originalScrollHeightoriginalScrollBottom); |
| 720 | | - } else { |
| 721 | | - chatBlock.scrollTo({ top: chatBlock.scrollHeight, behavior: 'auto' }); |
| 722 | 714 | } |
| 723 | 715 | } |
| 724 | 716 | export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, debounce_timeout.short); |