Use CSS resizing for send textarea

d27d750cb2888c6c8a7980f00cb08e4c55901041

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +30 -0Showing whitespace changes
public/scripts/RossAscends-mods.js+30 -0
@@ -887,7 +887,36 @@ export function initRossMods() {
887 saveSettingsDebounced();887 saveSettingsDebounced();
888 });888 });
889889
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;
@@ -895,6 +924,7 @@ export function initRossMods() {
895 const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight));924 const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight));
896 if (needsDebounce) autoFitSendTextAreaDebounced();925 if (needsDebounce) autoFitSendTextAreaDebounced();
897 else autoFitSendTextArea();926 else autoFitSendTextArea();
927 }
898 saveUserInputDebounced();928 saveUserInputDebounced();
899 });929 });
900930