From 8019277182cc757654fe3ab6657e57ae4664e496 Mon Sep 17 00:00:00 2001 From: dillonstreator Date: Fri, 27 Nov 2026 13:07:03 -0600 Subject: [PATCH] Match the speaker picker's badges to the timeline and keep it on screen. - People already in the session wear their session badge in the picker; unnamed speakers keep the dashed style. - The picker and Split dialog measure their height and open below, above, or as low as the window allows. --- .changeset/picker-badges-placement.md | 5 +++ .../renderer/src/components/Transcript.tsx | 43 +++++++++++++++---- .../renderer/src/hooks/useAnchoredPosition.ts | 35 +++++++++++++++ .../src/renderer/src/lib/placement.test.ts | 37 ++++++++++++++++ apps/lyra/src/renderer/src/lib/placement.ts | 23 ++++++++++ 5 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 .changeset/picker-badges-placement.md create mode 100644 apps/lyra/src/renderer/src/hooks/useAnchoredPosition.ts create mode 100644 apps/lyra/src/renderer/src/lib/placement.test.ts create mode 100644 apps/lyra/src/renderer/src/lib/placement.ts diff --git a/.changeset/picker-badges-placement.md b/.changeset/picker-badges-placement.md new file mode 100644 index 0000000..8ef8232 --- /dev/null +++ b/.changeset/picker-badges-placement.md @@ -0,0 +1,5 @@ +--- +'lyra': patch +--- + +The speaker picker shows each person with the same badge as the timeline and transcript, and stays fully on screen in a short window. diff --git a/apps/lyra/src/renderer/src/components/Transcript.tsx b/apps/lyra/src/renderer/src/components/Transcript.tsx index 192c456..91fe80d 100644 --- a/apps/lyra/src/renderer/src/components/Transcript.tsx +++ b/apps/lyra/src/renderer/src/components/Transcript.tsx @@ -19,6 +19,7 @@ import { } from '../../../shared/sessionDoc' import { expandToEdits, visibleText, type Span, type TranscriptEdit } from '../../../shared/transcriptOverlay' import type { NewSpeaker } from '../hooks/usePages' +import { useAnchoredPosition } from '../hooks/useAnchoredPosition' import { useDialogFocus } from '../hooks/useDialogFocus' import { rovingIndex } from '../lib/focus' import { clockLabel as clock } from '../lib/format' @@ -362,8 +363,7 @@ function SpeakerPicker({ ? `Who is ${speaker.name}?` : speaker.name const sample = line ?? own[0] - const top = Math.min(picker.anchor.bottom + 8, window.innerHeight - 420) - const left = Math.min(picker.anchor.left, window.innerWidth - 356) + const position = useAnchoredPosition(dialog, picker.anchor) const active = options[highlight] const count = justLine ? 1 : own.length @@ -398,11 +398,11 @@ function SpeakerPicker({
{ event.stopPropagation() }} @@ -516,7 +516,7 @@ function SpeakerPicker({ > {option.kind === 'person' ? ( <> - + {option.person.name} {option.person.self ? ' (you)' : ''} @@ -525,7 +525,11 @@ function SpeakerPicker({ ) : option.kind === 'speaker' ? ( <> - + {option.speaker.name} {justLine ? 'Move here' : 'Merge'} @@ -583,6 +587,28 @@ function SpeakerPicker({ ) } +/** + * A saved voice's badge in the picker: someone named in this session wears their speaker's + * badge, as on the timeline and the transcript; anyone else (a voice only suggested here + * included) their badge from Saved voices. + */ +function PersonBadge({ + person, + speakers, + people +}: { + person: Person + speakers: readonly SpeakerEntry[] + people: readonly Person[] +}) { + const here = speakers.find((entry) => entry.personId === person.id && stateOf(entry) === 'sure') + return here ? ( + + ) : ( + + ) +} + /** How well a saved voice matches, in plain words rather than a percentage. */ function MatchStrength({ score }: { score: number | null }) { if (score === null) return null @@ -624,8 +650,7 @@ function SplitDialog({ const valid = picked.size > 0 && picked.size < own.length const dialog = useRef(null) useDialogFocus(dialog, true) - const top = Math.min(anchor.bottom + 8, window.innerHeight - 440) - const left = Math.min(anchor.left, window.innerWidth - 536) + const position = useAnchoredPosition(dialog, anchor) const least = own[0]?.id return ( @@ -636,7 +661,7 @@ function SplitDialog({ role="dialog" aria-modal="true" aria-label={`Split ${speaker.name}`} - style={{ top: Math.max(8, top), left: Math.max(8, left) }} + style={position} onMouseDown={(event) => { event.stopPropagation() }} diff --git a/apps/lyra/src/renderer/src/hooks/useAnchoredPosition.ts b/apps/lyra/src/renderer/src/hooks/useAnchoredPosition.ts new file mode 100644 index 0000000..1b5b4df --- /dev/null +++ b/apps/lyra/src/renderer/src/hooks/useAnchoredPosition.ts @@ -0,0 +1,35 @@ +import { useLayoutEffect, useState, type RefObject } from 'react' +import { placeNear } from '../lib/placement' + +/** + * Positions a fixed popover in `ref` next to `anchor`, from its measured size rather than a + * guess: placed before paint, and again whenever its content (a filtered list, a hint) or the + * window changes size, so no part of it ends up off screen. + */ +export function useAnchoredPosition( + ref: RefObject, + anchor: DOMRect +): { top: number; left: number } { + const [position, setPosition] = useState({ top: anchor.bottom + 8, left: anchor.left }) + useLayoutEffect(() => { + const element = ref.current + if (!element) return + const place = (): void => { + const next = placeNear( + anchor, + { width: element.offsetWidth, height: element.offsetHeight }, + { width: window.innerWidth, height: window.innerHeight } + ) + setPosition((current) => (current.top === next.top && current.left === next.left ? current : next)) + } + place() + const observer = new ResizeObserver(place) + observer.observe(element) + window.addEventListener('resize', place) + return () => { + observer.disconnect() + window.removeEventListener('resize', place) + } + }, [ref, anchor]) + return position +} diff --git a/apps/lyra/src/renderer/src/lib/placement.test.ts b/apps/lyra/src/renderer/src/lib/placement.test.ts new file mode 100644 index 0000000..514aea2 --- /dev/null +++ b/apps/lyra/src/renderer/src/lib/placement.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, it } from 'vitest' +import { placeNear } from './placement' + +const view = { width: 360, height: 700 } + +describe('placeNear', () => { + it('goes below the anchor when it fits', () => { + expect(placeNear({ top: 100, bottom: 120, left: 20 }, { width: 320, height: 300 }, view)).toEqual({ + top: 128, + left: 20 + }) + }) + + it('goes above the anchor when there is no room below', () => { + expect(placeNear({ top: 600, bottom: 620, left: 20 }, { width: 320, height: 300 }, view)).toEqual({ + top: 292, + left: 20 + }) + }) + + it('sits at the bottom of the window when neither side has room', () => { + // 520 tall under an anchor at 162–178: below ends at 706, above starts at -366. + expect(placeNear({ top: 162, bottom: 178, left: 20 }, { width: 320, height: 520 }, view)).toEqual({ + top: 172, + left: 20 + }) + }) + + it('never starts above the top margin', () => { + expect(placeNear({ top: 300, bottom: 320, left: 20 }, { width: 320, height: 684 }, view).top).toBe(8) + }) + + it('keeps the right edge inside the window', () => { + expect(placeNear({ top: 100, bottom: 120, left: 200 }, { width: 320, height: 100 }, view).left).toBe(32) + expect(placeNear({ top: 100, bottom: 120, left: 0 }, { width: 520, height: 100 }, view).left).toBe(8) + }) +}) diff --git a/apps/lyra/src/renderer/src/lib/placement.ts b/apps/lyra/src/renderer/src/lib/placement.ts new file mode 100644 index 0000000..0101aa2 --- /dev/null +++ b/apps/lyra/src/renderer/src/lib/placement.ts @@ -0,0 +1,23 @@ +/** Space kept between a popover and its anchor, and between a popover and the window's edge. */ +const GAP = 8 +const MARGIN = 8 + +type Box = { width: number; height: number } + +/** + * Where a popover goes next to the thing it's about: below it, else above it, else as low as the + * window allows. Always fully inside the window, so every row and button in it can be reached + * (the popover's own max height is the window less the margins, so the last case always fits). + */ +export function placeNear( + anchor: { top: number; bottom: number; left: number }, + size: Box, + view: Box +): { top: number; left: number } { + const left = Math.max(MARGIN, Math.min(anchor.left, view.width - MARGIN - size.width)) + const below = anchor.bottom + GAP + if (below + size.height <= view.height - MARGIN) return { top: below, left } + const above = anchor.top - GAP - size.height + if (above >= MARGIN) return { top: above, left } + return { top: Math.max(MARGIN, view.height - MARGIN - size.height), left } +}