From 5253ff1fe3918df4ddf512e13f1e2eaa31b58313 Mon Sep 17 00:00:00 2001 From: Janick Spielmann Date: Wed, 28 Oct 2026 13:34:49 +0100 Subject: [PATCH] Keep weight/bias hovercard open while editing Previously the hovercard was tied to the mouse position: as soon as the pointer left the thin invisible link path, mouseleave closed the card and the input field with it, even in the middle of typing a value. Now clicking into the card pins it. It stays open when the pointer leaves the link or enters another one, and closes on Enter, Escape or a mouse press outside of the card. Plain hovering without a click behaves as before. The invisible hover path is also widened from 8 to 14 px to make the link easier to hit. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01K4U4bLzdEj7UET5p21Ltu3 --- src/playground.ts | 31 ++++++++++++++++++++++++++++--- styles.css | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/playground.ts b/src/playground.ts index aeac0f9c..cbf7b575 100644 --- a/src/playground.ts +++ b/src/playground.ts @@ -176,6 +176,14 @@ let lineChart = new AppendingLineChart(d3.select("#linechart"), ["#777", "black"]); function makeGUI() { + // Close a pinned hovercard when the user presses the mouse outside of it. + document.addEventListener("mousedown", (event: MouseEvent) => { + let card = document.getElementById("hovercard"); + if (hovercardPinned && !card.contains(event.target as Node)) { + closeHoverCard(); + } + }); + d3.select("#reset-button").on("click", () => { reset(); userHasInteracted(); @@ -702,8 +710,23 @@ function addPlusMinusControl(x: number, layerIdx: number) { ); } +/** + * While a weight or bias is being edited, the hovercard is pinned: moving the + * mouse off the link (or onto another one) no longer closes or replaces it. + * It closes on Enter, Escape or a mouse press outside of the card. + */ +let hovercardPinned = false; + +function closeHoverCard() { + hovercardPinned = false; + updateHoverCard(null); +} + function updateHoverCard(type: HoverType, nodeOrLink?: nn.Node | nn.Link, coordinates?: [number, number]) { + if (hovercardPinned) { + return; + } let hovercard = d3.select("#hovercard"); if (type == null) { hovercard.style("display", "none"); @@ -711,6 +734,7 @@ function updateHoverCard(type: HoverType, nodeOrLink?: nn.Node | nn.Link, return; } d3.select("#svg").on("click", () => { + hovercardPinned = true; hovercard.select(".value").style("display", "none"); let input = hovercard.select("input"); input.style("display", null); @@ -724,9 +748,10 @@ function updateHoverCard(type: HoverType, nodeOrLink?: nn.Node | nn.Link, updateUI(); } }); - input.on("keypress", () => { - if ((d3.event as any).keyCode === 13) { - updateHoverCard(type, nodeOrLink, coordinates); + input.on("keydown", () => { + let keyCode = (d3.event as any).keyCode; + if (keyCode === 13 || keyCode === 27) { + closeHoverCard(); } }); (input.node() as HTMLInputElement).focus(); diff --git a/styles.css b/styles.css index 87b9bc5d..a46f9585 100644 --- a/styles.css +++ b/styles.css @@ -707,7 +707,7 @@ g.column rect { /** Invisible thick links used for showing weight values on mouse hover. */ #network .core .link-hover { - stroke-width: 8; + stroke-width: 14; stroke: black; fill: none; opacity: 0;