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() {
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', () => {
919+ if (!cssAutofit) {
891920 const hasContent = sendTextArea.value !== '';
892921 const fitsCurrentSize = sendTextArea.scrollHeight <= sendTextArea.offsetHeight;
893922 const isScrollbarShown = sendTextArea.clientWidth < sendTextArea.offsetWidth;
@@ -895,6 +924,7 @@ export function initRossMods() {
895924 const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight));
896925 if (needsDebounce) autoFitSendTextAreaDebounced();
897926 else autoFitSendTextArea();
927+ }
898928 saveUserInputDebounced();
899929 });
900930