Use CSS resizing for send textarea

d27d750cb2888c6c8a7980f00cb08e4c55901041

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

1 files changed, +37 -7Ignore whitespace
public/scripts/RossAscends-mods.js+37 -7
@@ -887,14 +887,44 @@ export function initRossMods() {
887887 saveSettingsDebounced();
888888 });
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+
890918 sendTextArea.addEventListener('input', () => {
891- const hasContent = sendTextArea.value !== '';
919+ if (!cssAutofit) {
892920 const fitsCurrentSizehasContent = sendTextArea.scrollHeightvalue <!== sendTextArea.offsetHeight'';
893921 const isScrollbarShownfitsCurrentSize = sendTextArea.clientWidthscrollHeight <= sendTextArea.offsetWidthoffsetHeight;
894922 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+ }
898928 saveUserInputDebounced();
899929 });
900930