From 519af3b44b5e90e284a362a061225a72e32c3128 Mon Sep 17 00:00:00 2001 From: somebody Date: Tue, 11 Oct 2022 21:34:21 -0500 Subject: [PATCH] Tooltip: Shove cursor over --- static/koboldai.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/static/koboldai.js b/static/koboldai.js index dfd11d39..d1ee8abe 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -5048,8 +5048,17 @@ let load_substitutions; document.addEventListener("mousemove", function(event) { if (!tooltipActive) return; - tooltip.style.left = `${event.x}px`; - tooltip.style.top = `${event.y}px`; + + let [x, y] = [event.x, event.y]; + + // X + the tooltip's width is the farthest point right we will display; + // let's account for it. If we will render outside of the window, + // subtract accordingly. + let xOverflow = (x + tooltip.clientWidth) - window.innerWidth; + if (xOverflow > 0) x -= xOverflow; + + tooltip.style.left = `${x}px`; + tooltip.style.top = `${y}px`; }); // Inital scan