From 88b7797de46d1e6caa014b87e257009723389dbe Mon Sep 17 00:00:00 2001 From: Kaushal Poojary <101418328+Kaushal-Poojary@users.noreply.github.com> Date: Fri, 11 Aug 2023 03:08:39 +0530 Subject: [PATCH] Added debounce to mouseup event listener --- selection.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/selection.js b/selection.js index b919f3f..ff2fcee 100644 --- a/selection.js +++ b/selection.js @@ -274,27 +274,25 @@ const Selection = (function() { window.addEventListener( 'mouseup', - function() { - setTimeout(function mouseTimeout() { - if (hasTooltipDrawn()) { - if (hasSelection()) { - selection = window.getSelection(); - text = selection.toString(); - moveTooltip(); - return; - } else { - document.querySelector('.selection').remove(); - } - } + _.debounce(function() { + if (hasTooltipDrawn()) { if (hasSelection()) { selection = window.getSelection(); text = selection.toString(); - drawTooltip(); + moveTooltip(); + return; + } else { + document.querySelector('.selection').remove(); } - }, 10); - }, - false + } + if (hasSelection()) { + selection = window.getSelection(); + text = selection.toString(); + drawTooltip(); + } + }, 300) // Adjust the debounce delay as needed ); + } function config(options) {