| 887 | 887 | saveSettingsDebounced(); |
| 888 | 888 | }); |
| 889 | 889 | |
| 890 | + const cssAutofit = CSS.supports('field-sizing', 'content'); |
| 891 | + |
| 892 | + if (cssAutofit) { |
| 893 | + sendTextArea.style['fieldSizing'] = 'content'; |
| 894 | + sendTextArea.style['height'] = 'auto'; |
| 895 | + |
| 896 | + let lastHeight = chatBlock.offsetHeight; |
| 897 | + const chatBlockResizeObserver = new ResizeObserver((entries) => { |
| 898 | + for (const entry of entries) { |
| 899 | + if (entry.target !== chatBlock) { |
| 900 | + continue; |
| 901 | + } |
| 902 | + |
| 903 | + const threshold = 1; |
| 904 | + const newHeight = chatBlock.offsetHeight; |
| 905 | + const deltaHeight = newHeight - lastHeight; |
| 906 | + const isScrollAtBottom = Math.abs(chatBlock.scrollHeight - chatBlock.scrollTop - newHeight) <= threshold; |
| 907 | + |
| 908 | + if (!isScrollAtBottom && Math.abs(deltaHeight) > threshold) { |
| 909 | + chatBlock.scrollTop -= deltaHeight; |
| 910 | + } |
| 911 | + lastHeight = newHeight; |
| 912 | + } |
| 913 | + }); |
| 914 | + |
| 915 | + chatBlockResizeObserver.observe(chatBlock); |
| 916 | + } |
| 917 | + |
| 890 | 918 | sendTextArea.addEventListener('input', () => { |
| 891 | | - const hasContent = sendTextArea.value !== ''; |
| 919 | + if (!cssAutofit) { |
| 892 | 920 | const fitsCurrentSizehasContent = sendTextArea.scrollHeightvalue <!== sendTextArea.offsetHeight''; |
| 893 | 921 | const isScrollbarShownfitsCurrentSize = sendTextArea.clientWidthscrollHeight <= sendTextArea.offsetWidthoffsetHeight; |
| 894 | 922 | const isHalfScreenHeightisScrollbarShown = sendTextArea.offsetHeightclientWidth >=< windowsendTextArea.innerHeight / 2offsetWidth; |
| 895 | | - const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight)); |
| 923 | + const isHalfScreenHeight = sendTextArea.offsetHeight >= window.innerHeight / 2; |
| 896 | | - if (needsDebounce) autoFitSendTextAreaDebounced(); |
| 924 | + const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight)); |
| 897 | | - else autoFitSendTextArea(); |
| 925 | + if (needsDebounce) autoFitSendTextAreaDebounced(); |
| 926 | + else autoFitSendTextArea(); |
| 927 | + } |
| 898 | 928 | saveUserInputDebounced(); |
| 899 | 929 | }); |
| 900 | 930 | |