Move code for cleaner diff

252043ae11f51c637ebe1c5d3a58aae4352e3b2a

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

1 files changed, +20 -20Ignore whitespace
public/script.js+20 -20
@@ -9726,6 +9726,26 @@ jQuery(async function () {
97269726 });
97279727
97289728 const cssAutofit = CSS.supports('field-sizing', 'content');
9729+ if (!cssAutofit) {
9730+ /**
9731+ * Sets the scroll height of the edit textarea to fit the content.
9732+ * @param {HTMLTextAreaElement} e Textarea element to auto-fit
9733+ */
9734+ function autoFitEditTextArea(e) {
9735+ e.style.height = '0px';
9736+ const newHeight = e.scrollHeight + 4;
9737+ e.style.height = `${newHeight}px`;
9738+ }
9739+ const autoFitEditTextAreaDebounced = debounce(autoFitEditTextArea, debounce_timeout.short);
9740+ document.addEventListener('input', e => {
9741+ if (e.target instanceof HTMLTextAreaElement && e.target.classList.contains('edit_textarea')) {
9742+ const scrollbarShown = e.target.clientWidth < e.target.offsetWidth && e.target.offsetHeight >= window.innerHeight * 0.75;
9743+ const immediately = (e.target.scrollHeight > e.target.offsetHeight && !scrollbarShown) || e.target.value === '';
9744+ immediately ? autoFitEditTextArea(e.target) : autoFitEditTextAreaDebounced(e.target);
9745+ }
9746+ });
9747+ }
9748+
97299749 const chatElementScroll = document.getElementById('chat');
97309750 const chatScrollHandler = function () {
97319751 if (power_user.waifuMode) {
@@ -9748,26 +9768,6 @@ jQuery(async function () {
97489768 chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true });
97499769 chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true });
97509770
9751- if (!cssAutofit) {
9752- /**
9753- * Sets the scroll height of the edit textarea to fit the content.
9754- * @param {HTMLTextAreaElement} e Textarea element to auto-fit
9755- */
9756- function autoFitEditTextArea(e) {
9757- e.style.height = '0px';
9758- const newHeight = e.scrollHeight + 4;
9759- e.style.height = `${newHeight}px`;
9760- }
9761- const autoFitEditTextAreaDebounced = debounce(autoFitEditTextArea, debounce_timeout.short);
9762- document.addEventListener('input', e => {
9763- if (e.target instanceof HTMLTextAreaElement && e.target.classList.contains('edit_textarea')) {
9764- const scrollbarShown = e.target.clientWidth < e.target.offsetWidth && e.target.offsetHeight >= window.innerHeight * 0.75;
9765- const immediately = (e.target.scrollHeight > e.target.offsetHeight && !scrollbarShown) || e.target.value === '';
9766- immediately ? autoFitEditTextArea(e.target) : autoFitEditTextAreaDebounced(e.target);
9767- }
9768- });
9769- }
9770-
97719771 $(document).on('click', '.mes', function () {
97729772 //when a 'delete message' parent div is clicked
97739773 // and we are in delete mode and del_checkbox is visible