Skip to content
This repository was archived by the owner on Aug 17, 2026. It is now read-only.

Commit 70a16ab

Browse files
committed
fix(grunt/tui): #N ticket-hover — shadcn-svelte HoverCard parity (anchored near trigger, open/close delays, sticky) (#16)
Refs hivemind anomalyco#233. Closes Nik feedback after PR #15: 'works but I'd much rather want the thing that works like shadcn-svelte's hovercard'. ## What changed vs PR #15 PR #15 moved the tooltip to a fixed top-right screen anchor to fix the flicker. That worked but produced wrong UX — Nik wanted shadcn HoverCard ergonomics: card pops up NEAR the trigger after a small open delay, STAYS open if cursor moves into the card body (close delay gives time to traverse the gap), closes after a brief delay so a small detour doesn't dismiss it. ## How shadcn-style is achieved Hivemind context now owns: - hoveredTicket signal: { id, anchorX, anchorY } | null - triggerHoverEnter(id, x, y) — clears any pending close-timer, schedules open after OPEN_DELAY_MS (150ms) at the anchor coords - triggerHoverLeave() — cancels pending open if still scheduled; otherwise schedules close after CLOSE_DELAY_MS (200ms) so cursor can traverse to the card - setCardHovered(bool) — called by the card's own onMouseOver/Out. true cancels any pending close timer; false starts one. Sticky behavior emerges naturally: trigger leave fires close-timer → within 200ms cursor reaches card body → setCardHovered(true) cancels the timer → card stays. When cursor leaves card → setCardHovered(false) restarts the timer → card closes after 200ms. ## TicketRef changes onMouseOver now passes evt.x, evt.y to hive.triggerHoverEnter() so the card knows where to anchor. onMouseOut calls hive.triggerHoverLeave(). Click handler unchanged. ## TicketHoverCard changes - Reads anchor coords from hive.hoveredTicket() - Positions just below + slightly right of the cursor (left=anchorX+1, top=anchorY+1) - Right-edge overflow guard: if card would push off the right, flips so its right edge aligns at the cursor. - Bottom-edge guard: flips above the cursor if near terminal bottom. - Adds onMouseOver={hive.setCardHovered(true)} + onMouseOut={hive.setCardHovered(false)} for the sticky behavior. ## Why no flicker even though card is near trigger PR #15 was right that a per-ref tooltip overlapping its own text caused flicker. This PR keeps the single-instance shared-card pattern but moves the position from fixed top-right back to anchored-near-cursor. The flicker risk only re-emerges if the card overlapped the trigger text — but we offset by +1 in both axes, so the trigger column is always clear. And the sticky-hover state machine handles the gap traversal cleanly. ## Verified bun typecheck clean. Local install reports 1.15.10-grunt.7+local.f86e6640f.dirty.
1 parent 830fe33 commit 70a16ab

3 files changed

Lines changed: 173 additions & 88 deletions

File tree

Lines changed: 92 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,108 @@
1-
// grunt-it: single floating tooltip for hivemind ticket-ref hovers (#233).
1+
// grunt-it: shadcn-svelte HoverCard-style tooltip for hivemind ticket-ref hovers (#233).
22
//
3-
// Rendered ONCE at the app-root level (NOT as a child of any TicketRef). Reads the
4-
// global hoveredTicketId signal from the Hivemind context; when set, shows the ticket
5-
// detail at a fixed screen anchor (top of screen, right-aligned). When null, renders
6-
// nothing (and consumes no space).
3+
// Rendered ONCE at the app-root level. Reads the global hoveredTicket signal from the
4+
// Hivemind context; when set, shows the ticket detail at a position anchored near the
5+
// trigger's cursor coords (just below + slightly right, with right-edge overflow guard).
76
//
8-
// Architecture motivation: a per-ref tooltip box rendered inside the same column as
9-
// the ref's text caused a hover-flicker loop in v1 — the tooltip overlapped the text
10-
// region, mouse moved off the text onto the tooltip, onMouseOut fired, tooltip hid,
11-
// mouse was back on text, onMouseOver fired, tooltip showed again. By rendering the
12-
// tooltip at a screen anchor far from any mouse-interactive surface, the hover state
13-
// is stable.
7+
// Sticky-hover semantics: the card also has its own onMouseOver/Out — entering the card
8+
// cancels the trigger's close-timer (so the cursor can traverse the gap between trigger
9+
// and card without dismissing). Leaving the card schedules a close-timer of its own.
10+
// Net result: shadcn HoverCard ergonomics in the terminal.
1411

1512
import { Show } from "solid-js"
13+
import { useTerminalDimensions } from "@opentui/solid"
1614
import { useHivemind } from "../context/hivemind"
1715
import { useTheme } from "../context/theme"
1816

17+
const CARD_WIDTH = 60
18+
const CARD_MAX_HEIGHT = 16
19+
1920
export function TicketHoverCard() {
2021
const hive = useHivemind()
2122
const { theme } = useTheme()
23+
const dims = useTerminalDimensions()
2224

2325
return (
24-
<Show when={hive.hoveredTicketId() !== null}>
25-
<box
26-
position="absolute"
27-
top={1}
28-
right={2}
29-
backgroundColor={theme.backgroundPanel}
30-
border={true}
31-
borderColor={theme.border}
32-
paddingLeft={1}
33-
paddingRight={1}
34-
paddingTop={0}
35-
paddingBottom={0}
36-
zIndex={3000}
37-
maxWidth={70}
38-
>
39-
{(() => {
40-
const id = hive.hoveredTicketId()
41-
if (id === null) return null
42-
const d = hive.ticketDetail(id)
43-
if (d === undefined) {
44-
return <text fg={theme.textMuted}>loading #{id}...</text>
45-
}
46-
if (d === null) {
47-
return <text fg={theme.textMuted}>#{id}: not found</text>
26+
<Show when={hive.hoveredTicket()}>
27+
{(anchor) => {
28+
// Position: just below the trigger cursor, offset right by 2 cols. If that would
29+
// push off the right edge, flip the card so its right edge aligns with the cursor.
30+
const left = () => {
31+
const desired = anchor().anchorX + 1
32+
const overflow = desired + CARD_WIDTH - dims().width
33+
if (overflow > 0) return Math.max(0, anchor().anchorX - CARD_WIDTH)
34+
return desired
35+
}
36+
const top = () => {
37+
const desired = anchor().anchorY + 1
38+
// If near the bottom, flip above the cursor.
39+
if (desired + CARD_MAX_HEIGHT > dims().height) {
40+
return Math.max(0, anchor().anchorY - CARD_MAX_HEIGHT)
4841
}
49-
return (
50-
<>
51-
<text fg={theme.text} wrapMode="word">
52-
<b>
53-
#{d.id} {d.title}
54-
</b>
55-
</text>
56-
<text fg={theme.textMuted}>
57-
<span>{d.status}</span>
58-
{" · "}
59-
<span>{d.priority}</span>
60-
<Show when={d.zone}>
61-
{" · "}
62-
<span>zone={d.zone}</span>
63-
</Show>
64-
<Show when={d.owner}>
65-
{" · "}
66-
<span>owner={d.owner}</span>
67-
</Show>
68-
</text>
69-
<Show when={d.scope}>
70-
<text fg={theme.textMuted} wrapMode="word">
71-
{(d.scope ?? "").slice(0, 220)}
72-
{(d.scope ?? "").length > 220 ? "..." : ""}
73-
</text>
74-
</Show>
75-
<text fg={theme.textMuted}>
76-
<span>click to open in hivemind-ui</span>
77-
</text>
78-
</>
79-
)
80-
})()}
81-
</box>
42+
return desired
43+
}
44+
45+
return (
46+
<box
47+
position="absolute"
48+
left={left()}
49+
top={top()}
50+
backgroundColor={theme.backgroundPanel}
51+
border={true}
52+
borderColor={theme.border}
53+
paddingLeft={1}
54+
paddingRight={1}
55+
paddingTop={0}
56+
paddingBottom={0}
57+
zIndex={3000}
58+
maxWidth={CARD_WIDTH}
59+
onMouseOver={() => hive.setCardHovered(true)}
60+
onMouseOut={() => hive.setCardHovered(false)}
61+
>
62+
{(() => {
63+
const id = anchor().id
64+
const d = hive.ticketDetail(id)
65+
if (d === undefined) {
66+
return <text fg={theme.textMuted}>loading #{id}...</text>
67+
}
68+
if (d === null) {
69+
return <text fg={theme.textMuted}>#{id}: not found</text>
70+
}
71+
return (
72+
<>
73+
<text fg={theme.text} wrapMode="word">
74+
<b>
75+
#{d.id} {d.title}
76+
</b>
77+
</text>
78+
<text fg={theme.textMuted}>
79+
<span>{d.status}</span>
80+
{" · "}
81+
<span>{d.priority}</span>
82+
<Show when={d.zone}>
83+
{" · "}
84+
<span>zone={d.zone}</span>
85+
</Show>
86+
<Show when={d.owner}>
87+
{" · "}
88+
<span>owner={d.owner}</span>
89+
</Show>
90+
</text>
91+
<Show when={d.scope}>
92+
<text fg={theme.textMuted} wrapMode="word">
93+
{(d.scope ?? "").slice(0, 220)}
94+
{(d.scope ?? "").length > 220 ? "..." : ""}
95+
</text>
96+
</Show>
97+
<text fg={theme.textMuted}>
98+
<span>click to open in hivemind-ui</span>
99+
</text>
100+
</>
101+
)
102+
})()}
103+
</box>
104+
)
105+
}}
82106
</Show>
83107
)
84108
}

‎packages/opencode/src/cli/cmd/tui/component/ticket-ref.tsx‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// grunt-it: clickable hivemind ticket-ref (#229) component for assistant chat (#233).
22
//
3-
// v2 architecture (after v1 flicker bug):
4-
// - This component is just a colored clickable text. NO local tooltip — that was the source
5-
// of the flicker (per-ref tooltip box overlapped its own text, hover→unhover→hover loop).
6-
// - Hover/leave events set a SINGLE global "currentlyHoveredTicket" signal in the Hivemind
7-
// context. Detail fetch + caching also lives there (shared across all refs).
8-
// - The single floating <TicketHoverCard /> reads that signal and renders the detail at a
9-
// fixed screen anchor — no overlap with any text, so no flicker.
3+
// shadcn-svelte HoverCard parity: hover the trigger → after a small open delay the card
4+
// appears near the trigger; cursor can move INTO the card and it stays open; close happens
5+
// after a small leave delay so a brief detour doesn't dismiss it. All the timer + sticky
6+
// behavior lives in the Hivemind context — this component just emits hover-enter / leave +
7+
// the cursor coords for anchoring.
108
//
119
// Click opens hivemind-ui at /tasks/<id> in the system browser.
1210

@@ -16,6 +14,8 @@ import { useHivemind } from "../context/hivemind"
1614

1715
const HIVEMIND_UI_BASE = process.env.HIVEMIND_UI_BASE ?? "http://localhost:5173"
1816

17+
type MouseEventLike = { x: number; y: number }
18+
1919
export function TicketRef(props: { id: number }) {
2020
const { theme } = useTheme()
2121
const hive = useHivemind()
@@ -24,8 +24,12 @@ export function TicketRef(props: { id: number }) {
2424
<text
2525
fg={theme.markdownLink ?? theme.primary}
2626
attributes={1}
27-
onMouseOver={() => hive.setHoveredTicket(props.id)}
28-
onMouseOut={() => hive.setHoveredTicket(null)}
27+
onMouseOver={(evt: MouseEventLike) => {
28+
hive.triggerHoverEnter(props.id, evt.x, evt.y)
29+
}}
30+
onMouseOut={() => {
31+
hive.triggerHoverLeave()
32+
}}
2933
onMouseUp={() => {
3034
open(`${HIVEMIND_UI_BASE}/tasks/${props.id}`).catch(() => {})
3135
}}

‎packages/opencode/src/cli/cmd/tui/context/hivemind.tsx‎

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,26 @@ export const { use: useHivemind, provider: HivemindProvider } = createSimpleCont
218218
}
219219

220220
// ----- ticket-hover state (#233) ---------------------------------------------------------
221-
// One global "currently-hovered ticket id" signal. TicketRefs set/clear it on
222-
// enter/leave; the single floating TicketHoverCard reads it and renders the detail.
223-
// No per-ref tooltip boxes overlapping their own text → no flicker.
224-
const [hoveredTicketId, setHoveredTicketId] = createSignal<number | null>(null)
221+
// shadcn-svelte-style HoverCard: card pops up near the trigger after a small open delay,
222+
// STAYS open if the cursor moves into the card (close delay gives time to traverse the gap),
223+
// closes after a small leave delay so a brief detour doesn't dismiss it.
224+
//
225+
// Three signals power this:
226+
// hoveredTicket — { id, anchorX, anchorY } | null. What the card renders + anchors to.
227+
// The card itself also calls setCardHover(true/false) on its own onMouseOver/Out to
228+
// suppress the close timer while the cursor is inside the card body.
229+
type HoverAnchor = { id: number; anchorX: number; anchorY: number }
230+
const [hoveredTicket, setHoveredTicketSignal] = createSignal<HoverAnchor | null>(null)
225231
const ticketCache = new Map<number, TicketDetail | null>()
226232
const ticketInflight = new Map<number, Promise<TicketDetail | null>>()
227233
const [ticketCacheTick, setTicketCacheTick] = createSignal(0)
234+
let openTimer: ReturnType<typeof setTimeout> | undefined
235+
let closeTimer: ReturnType<typeof setTimeout> | undefined
236+
let cardHovered = false
237+
const OPEN_DELAY_MS = 150
238+
const CLOSE_DELAY_MS = 200
228239

229240
function ticketDetail(id: number): TicketDetail | null | undefined {
230-
// Read the tick so consumers re-render when the cache updates.
231241
ticketCacheTick()
232242
return ticketCache.get(id)
233243
}
@@ -262,10 +272,55 @@ export const { use: useHivemind, provider: HivemindProvider } = createSimpleCont
262272
return p
263273
}
264274

265-
function setHoveredTicket(id: number | null) {
266-
setHoveredTicketId(id)
267-
if (id !== null && !ticketCache.has(id)) {
268-
void fetchTicket(id)
275+
/** TicketRef calls this when mouse enters the trigger. Schedules the card open. */
276+
function triggerHoverEnter(id: number, anchorX: number, anchorY: number) {
277+
if (closeTimer) {
278+
clearTimeout(closeTimer)
279+
closeTimer = undefined
280+
}
281+
// Already showing this ticket? Just keep it open.
282+
const current = hoveredTicket()
283+
if (current?.id === id) return
284+
// Schedule open. If user moves off the trigger before delay elapses, openTimer is
285+
// cleared and nothing renders — no flash for accidental hovers.
286+
if (openTimer) clearTimeout(openTimer)
287+
openTimer = setTimeout(() => {
288+
openTimer = undefined
289+
setHoveredTicketSignal({ id, anchorX, anchorY })
290+
if (!ticketCache.has(id)) void fetchTicket(id)
291+
}, OPEN_DELAY_MS)
292+
}
293+
294+
/** TicketRef calls this when mouse leaves the trigger. Schedules close, can be cancelled
295+
* if the cursor moves into the card body (via setCardHovered(true)). */
296+
function triggerHoverLeave() {
297+
if (openTimer) {
298+
clearTimeout(openTimer)
299+
openTimer = undefined
300+
}
301+
if (closeTimer) clearTimeout(closeTimer)
302+
closeTimer = setTimeout(() => {
303+
closeTimer = undefined
304+
if (!cardHovered) setHoveredTicketSignal(null)
305+
}, CLOSE_DELAY_MS)
306+
}
307+
308+
/** TicketHoverCard calls this when mouse enters/leaves the card body. Entering keeps
309+
* the card open even after the trigger's leave-timer fires. */
310+
function setCardHovered(hovered: boolean) {
311+
cardHovered = hovered
312+
if (hovered) {
313+
if (closeTimer) {
314+
clearTimeout(closeTimer)
315+
closeTimer = undefined
316+
}
317+
} else {
318+
// Mouse left the card → start the close timer (in case the trigger is also unhovered).
319+
if (closeTimer) clearTimeout(closeTimer)
320+
closeTimer = setTimeout(() => {
321+
closeTimer = undefined
322+
if (!cardHovered) setHoveredTicketSignal(null)
323+
}, CLOSE_DELAY_MS)
269324
}
270325
}
271326

@@ -275,8 +330,10 @@ export const { use: useHivemind, provider: HivemindProvider } = createSimpleCont
275330
},
276331
refresh,
277332
// ticket-hover
278-
hoveredTicketId,
279-
setHoveredTicket,
333+
hoveredTicket,
334+
triggerHoverEnter,
335+
triggerHoverLeave,
336+
setCardHovered,
280337
ticketDetail,
281338
fetchTicket,
282339
}

0 commit comments

Comments
 (0)