From 6c02a12e880dfda8a96106c6f8770a00466185ff Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 12 Nov 2023 23:28:34 +0200 Subject: [PATCH] Proper manual input debounce --- public/script.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/script.js b/public/script.js index 59aba505a..7089ae839 100644 --- a/public/script.js +++ b/public/script.js @@ -9104,8 +9104,11 @@ jQuery(async function () { } }); + let manualInputTimeout; + $(document).on('input', '.range-block-counter input, .neo-range-input', function () { - setTimeout(() => { + clearTimeout(manualInputTimeout); + manualInputTimeout = setTimeout(() => { const caretPosition = saveCaretPosition($(this).get(0)); const myText = $(this).val().trim(); $(this).val(myText); // trim line breaks and spaces @@ -9171,7 +9174,7 @@ jQuery(async function () { restoreCaretPosition($(this).get(0), caretPosition); }, 2000); - }) + }); $(".user_stats_button").on('click', function () { userStatsHandler();