mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
Keep worktree lineage guides within the sidebar width
This commit is contained in:
+27
-10
@@ -59,7 +59,8 @@ export function buildLineageRowProjection(
|
||||
rows: readonly RenderRow[],
|
||||
groupBy: WorktreeGroupBy,
|
||||
newCardStyle: boolean,
|
||||
statusLane = newCardStyle
|
||||
statusLane = newCardStyle,
|
||||
guideWidth = Infinity
|
||||
) {
|
||||
const rowIndexByKey = new Map<string, number>()
|
||||
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'),
|
||||
|
||||
@@ -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 (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
data-worktree-lineage-guides=""
|
||||
className={cn('pointer-events-none absolute inset-0', hidden && 'opacity-0')}
|
||||
className="pointer-events-none absolute inset-0"
|
||||
>
|
||||
{railXs(guides.rails).map((x) => (
|
||||
<span
|
||||
|
||||
@@ -185,10 +185,11 @@ export function renderWorktreeVirtualRow(
|
||||
? getWorkspaceStatus(row.worktree, ctx.workspaceStatuses)
|
||||
: null
|
||||
const itemKey = folder ? null : getWorktreeHostIdentity(row.worktree)
|
||||
const guidesInDraggedRange = ctx.hiddenDragRanges.some(
|
||||
({ start, end }) => vItem.index >= start && vItem.index <= end
|
||||
)
|
||||
const sourceHidden =
|
||||
itemKey !== null &&
|
||||
ctx.worktreeDragState.draggingWorktreeId !== null &&
|
||||
ctx.hiddenDragRanges.some(({ start, end }) => vItem.index >= start && vItem.index <= end)
|
||||
itemKey !== null && ctx.worktreeDragState.draggingWorktreeId !== null && guidesInDraggedRange
|
||||
const itemPreviewOffset =
|
||||
(itemKey
|
||||
? ctx.worktreeDragState.previewOffsetsByWorktreeId.get(
|
||||
@@ -269,7 +270,7 @@ export function renderWorktreeVirtualRow(
|
||||
<LineageGuides
|
||||
guides={frame.guides}
|
||||
before={frame.before}
|
||||
hidden={sourceHidden || familyHidden}
|
||||
hidden={guidesInDraggedRange || familyHidden}
|
||||
/>
|
||||
)}
|
||||
<div className={cn('relative', sourceHidden && 'pointer-events-none opacity-0')}>
|
||||
|
||||
+6
-1
@@ -1,5 +1,6 @@
|
||||
import React, { useCallback, useMemo, useRef, useState } from 'react'
|
||||
import { useAppStore } from '@/store'
|
||||
import { useMeasuredWidth } from '@/components/right-sidebar/right-sidebar-measured-width'
|
||||
import { createProgrammaticScrollMarks } from '@/hooks/programmatic-scroll-marks'
|
||||
import { selectSidebarLineageParentIdentities } from '@/store/slices/worktrees/metadata/cross-store-lineage-parents'
|
||||
import { useProjectHeaderHostContexts } from './use-project-header-host-contexts'
|
||||
@@ -68,6 +69,8 @@ export const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktr
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
// Why: callback-ref only mutates scrollRef; state re-runs the scroll-to-top listener attach.
|
||||
const [scrollElement, setScrollElement] = useState<HTMLDivElement | null>(null)
|
||||
const [guideWidth, setGuideWidth] = useState<number | null>(null)
|
||||
const measureContentWidth = useMeasuredWidth(setGuideWidth)
|
||||
const settings = useAppStore((s) => s.settings)
|
||||
const worktreeVisibilityDefaultsByHost = useAppStore((s) => s.worktreeVisibilityDefaultsByHost)
|
||||
const lineageParentIdentities = useAppStore(selectSidebarLineageParentIdentities)
|
||||
@@ -130,7 +133,8 @@ export const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktr
|
||||
const renderRows = rows
|
||||
const { projection, activeFamilyRoots, firstHeaderIndex } = useLineageRowProjection({
|
||||
...rowProps,
|
||||
newCardStyle
|
||||
newCardStyle,
|
||||
guideWidth
|
||||
})
|
||||
|
||||
const headerDrag = useWorktreeSidebarHeaderDrag({
|
||||
@@ -403,6 +407,7 @@ export const VirtualizedWorktreeViewport = React.memo(function VirtualizedWorktr
|
||||
<div
|
||||
role="presentation"
|
||||
data-worktree-sidebar-content
|
||||
ref={measureContentWidth}
|
||||
className="relative w-full"
|
||||
style={{ height: `${virtualization.virtualizer.getTotalSize()}px` }}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user