Move code for cleaner diff

This commit is contained in:
Cohee
2024-12-21 17:33:18 +02:00
parent 85ce522270
commit 252043ae11

View File

@ -9726,6 +9726,26 @@ jQuery(async function () {
});
const cssAutofit = CSS.supports('field-sizing', 'content');
if (!cssAutofit) {
/**
* Sets the scroll height of the edit textarea to fit the content.
* @param {HTMLTextAreaElement} e Textarea element to auto-fit
*/
function autoFitEditTextArea(e) {
e.style.height = '0px';
const newHeight = e.scrollHeight + 4;
e.style.height = `${newHeight}px`;
}
const autoFitEditTextAreaDebounced = debounce(autoFitEditTextArea, debounce_timeout.short);
document.addEventListener('input', e => {
if (e.target instanceof HTMLTextAreaElement && e.target.classList.contains('edit_textarea')) {
const scrollbarShown = e.target.clientWidth < e.target.offsetWidth && e.target.offsetHeight >= window.innerHeight * 0.75;
const immediately = (e.target.scrollHeight > e.target.offsetHeight && !scrollbarShown) || e.target.value === '';
immediately ? autoFitEditTextArea(e.target) : autoFitEditTextAreaDebounced(e.target);
}
});
}
const chatElementScroll = document.getElementById('chat');
const chatScrollHandler = function () {
if (power_user.waifuMode) {
@ -9748,26 +9768,6 @@ jQuery(async function () {
chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true });
chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true });
if (!cssAutofit) {
/**
* Sets the scroll height of the edit textarea to fit the content.
* @param {HTMLTextAreaElement} e Textarea element to auto-fit
*/
function autoFitEditTextArea(e) {
e.style.height = '0px';
const newHeight = e.scrollHeight + 4;
e.style.height = `${newHeight}px`;
}
const autoFitEditTextAreaDebounced = debounce(autoFitEditTextArea, debounce_timeout.short);
document.addEventListener('input', e => {
if (e.target instanceof HTMLTextAreaElement && e.target.classList.contains('edit_textarea')) {
const scrollbarShown = e.target.clientWidth < e.target.offsetWidth && e.target.offsetHeight >= window.innerHeight * 0.75;
const immediately = (e.target.scrollHeight > e.target.offsetHeight && !scrollbarShown) || e.target.value === '';
immediately ? autoFitEditTextArea(e.target) : autoFitEditTextAreaDebounced(e.target);
}
});
}
$(document).on('click', '.mes', function () {
//when a 'delete message' parent div is clicked
// and we are in delete mode and del_checkbox is visible