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
This commit is contained in:
abaevbog 2024-08-09 09:23:31 -07:00 committed by GitHub
parent 69b4789c17
commit a7eb49162e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,12 +36,14 @@ var Zotero_Tooltip = new function () {
var timeoutID; var timeoutID;
var x; var x;
var y; var y;
var skip = false;
/** /**
* Start tracking the mouse and show a tooltip after it stops * Start tracking the mouse and show a tooltip after it stops
*/ */
this.start = function (tooltipText) { this.start = function (tooltipText) {
window.addEventListener('mousemove', handleMouseMove); window.addEventListener('mousemove', handleMouseMove);
window.addEventListener('mousedown', handleMouseDown);
text = tooltipText; text = tooltipText;
}; };
@ -50,13 +52,27 @@ var Zotero_Tooltip = new function () {
*/ */
this.stop = function () { this.stop = function () {
window.removeEventListener('mousemove', handleMouseMove); window.removeEventListener('mousemove', handleMouseMove);
window.removeEventListener('mousedown', handleMouseDown);
clearTimeout(timeoutID); clearTimeout(timeoutID);
// Mozilla hides the tooltip as soon as the mouse leaves the element, which is also different // Mozilla hides the tooltip as soon as the mouse leaves the element, which is also different
// from macOS behavior // from macOS behavior
hidePopup(); 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) { function handleMouseMove(event) {
// Do nothing if any mouse key is being pressed
if (event.buttons) return;
if (timeoutID) { if (timeoutID) {
clearTimeout(timeoutID); clearTimeout(timeoutID);
} }
@ -66,6 +82,7 @@ var Zotero_Tooltip = new function () {
} }
function handleMouseStop() { function handleMouseStop() {
if (skip) return;
var tooltipElem = document.getElementById('fake-tooltip'); var tooltipElem = document.getElementById('fake-tooltip');
// Create the fake tooltip if it does not exist // Create the fake tooltip if it does not exist
if (!tooltipElem) { if (!tooltipElem) {