| 887 | saveSettingsDebounced(); | 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 | sendTextArea.addEventListener('input', () => { | 918 | sendTextArea.addEventListener('input', () => { |
| | 919 | if (!cssAutofit) { |
| 891 | const hasContent = sendTextArea.value !== ''; | 920 | const hasContent = sendTextArea.value !== ''; |
| 892 | const fitsCurrentSize = sendTextArea.scrollHeight <= sendTextArea.offsetHeight; | 921 | const fitsCurrentSize = sendTextArea.scrollHeight <= sendTextArea.offsetHeight; |
| 893 | const isScrollbarShown = sendTextArea.clientWidth < sendTextArea.offsetWidth; | 922 | const isScrollbarShown = sendTextArea.clientWidth < sendTextArea.offsetWidth; |