diff --git a/src/renderer/src/components/sidebar/worktree-list/listing/lineage-row-projection.ts b/src/renderer/src/components/sidebar/worktree-list/listing/lineage-row-projection.ts index 359ba844a2f..55e1592485e 100644 --- a/src/renderer/src/components/sidebar/worktree-list/listing/lineage-row-projection.ts +++ b/src/renderer/src/components/sidebar/worktree-list/listing/lineage-row-projection.ts @@ -59,7 +59,8 @@ export function buildLineageRowProjection( rows: readonly RenderRow[], groupBy: WorktreeGroupBy, newCardStyle: boolean, - statusLane = newCardStyle + statusLane = newCardStyle, + guideWidth = Infinity ) { const rowIndexByKey = new Map() const rowKeys: string[] = [] @@ -183,21 +184,29 @@ export function buildLineageRowProjection( let branch: LineageRowGuides['branch'] = null const parent = frame.parent if (parent !== null) { - branch = { - x: guideX(index), - to: frame.left + BRANCH_END_INSET, - last: frame.end === frames[parent].end + if (guideX(index) < guideWidth) { + branch = { + x: guideX(index), + to: Math.min(frame.left + BRANCH_END_INSET, guideWidth), + last: frame.end === frames[parent].end + } } // Why: this runs for every row before virtualization, so extend the parent's shared rail list // in O(1) instead of walking or copying ancestors; only visible rows walk it to paint. const parentRails = frames[parent].guides!.rails const grandparent = frames[parent].parent rails = - grandparent !== null && frames[parent].end < frames[grandparent].end + grandparent !== null && + frames[parent].end < frames[grandparent].end && + guideX(parent) < guideWidth ? { x: guideX(parent), next: parentRails } : parentRails } - frame.guides = { rails, branch, stem: hasChildren ? guideX(index + 1) : null } + frame.guides = { + rails, + branch, + stem: hasChildren && guideX(index + 1) < guideWidth ? guideX(index + 1) : null + } }) return { frames, occurrencesByIdentity, rowIndexByKey, restoreSignal: JSON.stringify(rowKeys) } } @@ -220,14 +229,22 @@ export function useLineageRowProjection(args: { rows: RenderRow[] groupBy: WorktreeGroupBy newCardStyle: boolean + guideWidth: number | null activeWorktreeId: string | null activeWorkspaceExecutionHostId: ExecutionHostId | null }) { - const { rows, groupBy, newCardStyle, activeWorktreeId, activeWorkspaceExecutionHostId } = args + const { + rows, + groupBy, + newCardStyle, + guideWidth, + activeWorktreeId, + activeWorkspaceExecutionHostId + } = args const statusLane = useAppStore((s) => s.worktreeCardProperties.includes('status')) && newCardStyle const projection = useMemo( - () => buildLineageRowProjection(rows, groupBy, newCardStyle, statusLane), - [rows, groupBy, newCardStyle, statusLane] + () => buildLineageRowProjection(rows, groupBy, newCardStyle, statusLane, guideWidth ?? 0), + [rows, groupBy, newCardStyle, statusLane, guideWidth] ) const firstHeaderIndex = useMemo( () => rows.findIndex((row) => row.type === 'header' || row.type === 'host-header'), diff --git a/src/renderer/src/components/sidebar/worktree-list/rows/lineage-guides.tsx b/src/renderer/src/components/sidebar/worktree-list/rows/lineage-guides.tsx index a6bfb640de5..bba5c418a7f 100644 --- a/src/renderer/src/components/sidebar/worktree-list/rows/lineage-guides.tsx +++ b/src/renderer/src/components/sidebar/worktree-list/rows/lineage-guides.tsx @@ -1,5 +1,4 @@ import React from 'react' -import { cn } from '@/lib/class-names' import type { LineageRail, LineageRowGuides } from '../listing/lineage-row-projection' // Why: the card's title row center; single-line cards override it in CSS via :has(). @@ -24,14 +23,18 @@ export function LineageGuides({ guides: LineageRowGuides before: number hidden: boolean -}): React.JSX.Element { +}): React.JSX.Element | null { + if (hidden) { + return null + } + const titleCenter = `calc(${before}px + ${TITLE_CENTER})` const { branch } = guides return (