From 943514aa21141a256ed2a54514d2d0fd87c5a0db Mon Sep 17 00:00:00 2001 From: Alexopus Date: Thu, 1 Jan 2026 20:09:14 +0100 Subject: [PATCH] Fix phantom tooltip appearing after mouse leaves tag --- web/js/textHighlight.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/js/textHighlight.js b/web/js/textHighlight.js index 4d986f0..61a310e 100644 --- a/web/js/textHighlight.js +++ b/web/js/textHighlight.js @@ -276,11 +276,23 @@ async function syncText(inputEl, overlayEl, tries = 1) { overlayEl.innerHTML = result; } +// Track the current tooltip request to allow cancellation +let currentTooltipRequest = null; + async function showTagTooltip(element, tag) { - let tooltip = document.getElementById("tag-tooltip"); + // Create a cancellation token for this request + const requestId = Symbol('tooltip-request'); + currentTooltipRequest = requestId; + const description = (await booruApi.getTagDescription(tag)) ?? "No description available."; + // Check if this request was cancelled while we were fetching + if (currentTooltipRequest !== requestId) { + return; + } + + let tooltip = document.getElementById("tag-tooltip"); if (!tooltip) { tooltip = document.createElement("div"); tooltip.id = "tag-tooltip"; @@ -329,6 +341,9 @@ async function showTagTooltip(element, tag) { } function hideTagTooltip() { + // Cancel any pending tooltip request + currentTooltipRequest = null; + const tooltips = document.querySelectorAll("#tag-tooltip"); tooltips.forEach((tooltip) => { tooltip.remove();