From ebeac7ba40450962bfba46c9c7b9d7eefb829225 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 9 Jan 2024 13:21:57 -0400 Subject: client: hide tooltip right away when clicking elsewhere --- src/static/client3.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/static/client3.js b/src/static/client3.js index 35d9ab69..deeac6aa 100644 --- a/src/static/client3.js +++ b/src/static/client3.js @@ -1032,6 +1032,33 @@ function addHoverableTooltipPageListeners() { hideCurrentlyShownTooltip(); } }); + + document.body.addEventListener('click', domEvent => { + const {clientX, clientY} = domEvent; + + const pointIsOverHoverableOrTooltip = + pointIsOverAnyOf(getHoverablesAndTooltips()); + + if (!pointIsOverHoverableOrTooltip(clientX, clientY)) { + // Hide with "intent to replace" - we aren't actually going to replace + // the tooltip with a new one, but this intent indicates that it should + // be hidden right away, instead of showing. What we're really replacing, + // or rather removing, is the state of interacting with tooltips at all. + hideCurrentlyShownTooltip(true); + + // Part of that state is fast hovering, which should be canceled out. + state.fastHovering = false; + if (state.endFastHoveringTimeout) { + clearTimeout(state.endFastHoveringTimeout); + state.endFastHoveringTimeout = null; + } + + // Also cancel out of transitioning a tooltip hidden - this isn't caught + // by `hideCurrentlyShownTooltip` because a transitioning-hidden tooltip + // doesn't count as "shown" anymore. + cancelTransitioningTooltipHidden(); + } + }); } clientSteps.addPageListeners.push(addHoverableTooltipPageListeners); -- cgit 1.3.0-6-gf8a5