From a7eb49162e839d48e7d3aa058cfc3f07bf18bfc7 Mon Sep 17 00:00:00 2001 From: abaevbog Date: Fri, 9 Aug 2024 09:23:31 -0700 Subject: [PATCH] tweaks to Zotero_Tooltip behavior (#4523) - hide tooltip on click and make sure it does not appear for a bit to avoid race conditions (e.g. clicking right after mousemove stopped) - do not display a tooltip if a mouse key is being held (e.g. during drag in itemTree) Fixes: #4519 --- chrome/content/zotero/components/tooltip.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/chrome/content/zotero/components/tooltip.js b/chrome/content/zotero/components/tooltip.js index b58131fd40..e923d1486c 100644 --- a/chrome/content/zotero/components/tooltip.js +++ b/chrome/content/zotero/components/tooltip.js @@ -36,12 +36,14 @@ var Zotero_Tooltip = new function () { var timeoutID; var x; var y; + var skip = false; /** * Start tracking the mouse and show a tooltip after it stops */ this.start = function (tooltipText) { window.addEventListener('mousemove', handleMouseMove); + window.addEventListener('mousedown', handleMouseDown); text = tooltipText; }; @@ -50,13 +52,27 @@ var Zotero_Tooltip = new function () { */ this.stop = function () { window.removeEventListener('mousemove', handleMouseMove); + window.removeEventListener('mousedown', handleMouseDown); clearTimeout(timeoutID); // Mozilla hides the tooltip as soon as the mouse leaves the element, which is also different // from macOS behavior hidePopup(); }; + + // On click, hide current tooltip and do not show a new one for + // a bit to avoid a race condition when a tooltip might still appear + // if the click occurent right after the mouse stopped moving + function handleMouseDown() { + skip = true; + Zotero_Tooltip.stop(); + setTimeout(() => { + skip = false; + }, MOUSE_STOP_DELAY * 2); + } function handleMouseMove(event) { + // Do nothing if any mouse key is being pressed + if (event.buttons) return; if (timeoutID) { clearTimeout(timeoutID); } @@ -66,6 +82,7 @@ var Zotero_Tooltip = new function () { } function handleMouseStop() { + if (skip) return; var tooltipElem = document.getElementById('fake-tooltip'); // Create the fake tooltip if it does not exist if (!tooltipElem) {