From c90284626f46c49683776becf475c15c1ead9643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 15 Feb 2023 20:18:16 -0500 Subject: [PATCH] fix: dupe quote button, increase delay, hide immediately on empty selection --- public/src/client/topic/postTools.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index 082a03c919..9a42771e4a 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -467,7 +467,7 @@ define('forum/topic/postTools', [ warning.modal(); } - const selectionChangeFn = utils.debounce(selectionChange, 100); + const selectionChangeFn = utils.debounce(selectionChange, 250); function handleSelectionTooltip() { if (!ajaxify.data.privileges['topics:reply']) { @@ -475,15 +475,19 @@ define('forum/topic/postTools', [ } hooks.onPage('action:posts.loaded', delayedTooltip); - - $(document).off('selectionchange', selectionChangeFn).on('selectionchange', selectionChangeFn); + $(document).off('selectionchange'); + $(document).on('selectionchange', function () { + const selectionEmpty = window.getSelection().toString() === ''; + if (selectionEmpty) { + $('[component="selection/tooltip"]').addClass('hidden'); + } + }); + $(document).on('selectionchange', selectionChangeFn); } function selectionChange() { const selectionEmpty = window.getSelection().toString() === ''; - if (selectionEmpty) { - $('[component="selection/tooltip"]').addClass('hidden'); - } else { + if (!selectionEmpty) { delayedTooltip(); } } @@ -515,6 +519,7 @@ define('forum/topic/postTools', [ if (!selectionTooltip.length) { selectionTooltip = await app.parseAndTranslate('partials/topic/selection-tooltip', ajaxify.data); + $('[component="selection/tooltip"]').remove(); selectionTooltip.addClass('hidden').appendTo('body'); } selectionTooltip.off('click').on('click', '[component="selection/tooltip/quote"]', function () {