mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Use CSS resizing for send textarea
This commit is contained in:
@@ -887,7 +887,36 @@ export function initRossMods() {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cssAutofit = CSS.supports('field-sizing', 'content');
|
||||||
|
|
||||||
|
if (cssAutofit) {
|
||||||
|
sendTextArea.style['fieldSizing'] = 'content';
|
||||||
|
sendTextArea.style['height'] = 'auto';
|
||||||
|
|
||||||
|
let lastHeight = chatBlock.offsetHeight;
|
||||||
|
const chatBlockResizeObserver = new ResizeObserver((entries) => {
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry.target !== chatBlock) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const threshold = 1;
|
||||||
|
const newHeight = chatBlock.offsetHeight;
|
||||||
|
const deltaHeight = newHeight - lastHeight;
|
||||||
|
const isScrollAtBottom = Math.abs(chatBlock.scrollHeight - chatBlock.scrollTop - newHeight) <= threshold;
|
||||||
|
|
||||||
|
if (!isScrollAtBottom && Math.abs(deltaHeight) > threshold) {
|
||||||
|
chatBlock.scrollTop -= deltaHeight;
|
||||||
|
}
|
||||||
|
lastHeight = newHeight;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chatBlockResizeObserver.observe(chatBlock);
|
||||||
|
}
|
||||||
|
|
||||||
sendTextArea.addEventListener('input', () => {
|
sendTextArea.addEventListener('input', () => {
|
||||||
|
if (!cssAutofit) {
|
||||||
const hasContent = sendTextArea.value !== '';
|
const hasContent = sendTextArea.value !== '';
|
||||||
const fitsCurrentSize = sendTextArea.scrollHeight <= sendTextArea.offsetHeight;
|
const fitsCurrentSize = sendTextArea.scrollHeight <= sendTextArea.offsetHeight;
|
||||||
const isScrollbarShown = sendTextArea.clientWidth < sendTextArea.offsetWidth;
|
const isScrollbarShown = sendTextArea.clientWidth < sendTextArea.offsetWidth;
|
||||||
@@ -895,6 +924,7 @@ export function initRossMods() {
|
|||||||
const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight));
|
const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight));
|
||||||
if (needsDebounce) autoFitSendTextAreaDebounced();
|
if (needsDebounce) autoFitSendTextAreaDebounced();
|
||||||
else autoFitSendTextArea();
|
else autoFitSendTextArea();
|
||||||
|
}
|
||||||
saveUserInputDebounced();
|
saveUserInputDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user