| 9169 | 9169 | chooseBogusFolder($(this), tagId); |
| 9170 | 9170 | }); |
| 9171 | 9171 | |
| 9172 | | - $(document).on('input', '.edit_textarea', function () { |
| 9172 | + /** |
| 9173 | | - scroll_holder = $('#chat').scrollTop(); |
| 9173 | + * Sets the scroll height of the edit textarea to fit the content. |
| 9174 | | - $(this).height(0).height(this.scrollHeight); |
| 9174 | + * @param {HTMLTextAreaElement} e Textarea element to auto-fit |
| 9175 | + */ |
| 9176 | + function autoFitEditTextArea(e) { |
| 9177 | + scroll_holder = chatElement[0].scrollTop; |
| 9178 | + e.style.height = '0'; |
| 9179 | + e.style.height = `${e.scrollHeight + 4}px`; |
| 9175 | 9180 | is_use_scroll_holder = true; |
| 9181 | + } |
| 9182 | + const autoFitEditTextAreaDebounced = debounce(autoFitEditTextArea, debounce_timeout.short); |
| 9183 | + document.addEventListener('input', e => { |
| 9184 | + if (e.target instanceof HTMLTextAreaElement && e.target.classList.contains('edit_textarea')) { |
| 9185 | + const immediately = e.target.scrollHeight > e.target.offsetHeight || e.target.value === ''; |
| 9186 | + immediately ? autoFitEditTextArea(e.target) : autoFitEditTextAreaDebounced(e.target); |
| 9187 | + } |
| 9176 | 9188 | }); |
| 9177 | 9189 | $document.getElementById('#chat').onaddEventListener('scroll', function () { |
| 9178 | 9190 | if (is_use_scroll_holder) { |
| 9179 | | - $('#chat').scrollTop(scroll_holder); |
| 9191 | + this.scrollTop = scroll_holder; |
| 9180 | 9192 | is_use_scroll_holder = false; |
| 9181 | 9193 | } |
| 9182 | 9194 | }); |