[BUG] UI shifting in mobile browser #2488

ed0e522c6de7054b14efc7a72e17d5dcde0e7dcc

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

2 files changed, +28 -1Ignore whitespace
public/script.js+2 -1
@@ -155,6 +155,7 @@ import {
155155 ensureImageFormatSupported,
156156 flashHighlight,
157157 isTrueBoolean,
158+ debouncedThrottle,
158159} from './scripts/utils.js';
159160import { debounce_timeout } from './scripts/constants.js';
160161
@@ -9236,7 +9237,7 @@ jQuery(async function () {
92369237 e.style.height = `${e.scrollHeight + 4}px`;
92379238 is_use_scroll_holder = true;
92389239 }
92399240 const autoFitEditTextAreaDebounced = debouncedebouncedThrottle(autoFitEditTextArea, debounce_timeout.shortstandard);
92409241 document.addEventListener('input', e => {
92419242 if (e.target instanceof HTMLTextAreaElement && e.target.classList.contains('edit_textarea')) {
92429243 const immediately = e.target.scrollHeight > e.target.offsetHeight || e.target.value === '';
public/scripts/utils.js+26 -0
@@ -302,6 +302,32 @@ export function throttle(func, limit = 300) {
302302}
303303
304304/**
305+ * Creates a debounced throttle function that only invokes func at most once per every limit milliseconds.
306+ * @param {function} func The function to throttle.
307+ * @param {number} [limit=300] The limit in milliseconds.
308+ * @returns {function} The throttled function.
309+ */
310+export function debouncedThrottle(func, limit = 300) {
311+ let last, deferTimer;
312+ let db = debounce(func);
313+
314+ return function() {
315+ let now = +new Date, args = arguments;
316+ if(!last || (last && now < last + limit)) {
317+ clearTimeout(deferTimer);
318+ db.apply(this, args);
319+ deferTimer = setTimeout(function() {
320+ last = now;
321+ func.apply(this, args);
322+ }, limit);
323+ } else {
324+ last = now;
325+ func.apply(this, args);
326+ }
327+ };
328+}
329+
330+/**
305331 * Checks if an element is in the viewport.
306332 * @param {Element} el The element to check.
307333 * @returns {boolean} True if the element is in the viewport, false otherwise.