Improve worktree card interactions and spacing

- Let users toggle cards by clicking their headers.
- Delay details until the pointer rests to avoid accidental popups.
- Add breathing room around card content.
This commit is contained in:
Jinjing
2026-11-12 23:46:24 -08:00
parent d68c5ddc2d
commit dee296f6bf
8 changed files with 51 additions and 14 deletions
+1 -1
View File
@@ -1732,7 +1732,7 @@ html.native-shell .app-layout {
/* 2.0 leading icon: the latest tab in front, older tabs peeking above it as narrower, dimmer cards.
The box is the front tile only, so it centers on the title; layers overflow upward, staying
within the card's 6px top padding because the card surface clips. */
within the card's 8px top padding because the card surface clips. */
.worktree-card-leading-icon {
position: relative;
display: inline-block;
@@ -233,7 +233,7 @@ export function WorktreeCardSlotContent({
</>
)
const toggleCard = (event: React.MouseEvent<HTMLButtonElement>): void => {
const toggleCard = (event: React.MouseEvent<HTMLElement>): void => {
dispatchSuppressScrollAdjustment()
// Opening a card shows everything it holds, its child workspaces included.
if (!open && lineageCollapsed && onLineageToggle) {
@@ -257,6 +257,19 @@ export function WorktreeCardSlotContent({
<div
className="group/worktree-card flex min-w-0 flex-col"
data-worktree-card-hover-trigger=""
// The chevron is a small target; a plain click anywhere on the header toggles too.
onClick={(event) => {
if (
canOpen &&
!pickingSendTarget &&
!event.defaultPrevented &&
event.detail <= 1 &&
!(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) &&
!window.getSelection()?.toString()
) {
toggleCard(event)
}
}}
>
<div
className={cn(
@@ -44,7 +44,7 @@ export type WorktreeCardProps = {
lineageDescendantIdentities?: WorktreeLineageSource
lineageChildren?: React.ReactNode
lineageChildrenStyle?: React.CSSProperties
onLineageToggle?: (event: React.MouseEvent<HTMLButtonElement>) => void
onLineageToggle?: (event: React.MouseEvent<HTMLElement>) => void
isLineageDropTarget?: boolean
onActivate?: () => void
onWorktreeCardClick?: () => void
@@ -25,6 +25,7 @@ import { WorktreeCardTaskDetailSection } from '../review/WorktreeCardTaskDetailS
import { getWorktreeCardTaskActions } from '../review/worktree-card-task-actions'
import { WorktreeCardHoverIdentityHeader } from './WorktreeCardHoverIdentityHeader'
import { CommentMarkdownAsync, preloadCommentMarkdown } from '../../comment-markdown-lazy'
import { useActivityThreadHoverCardIntent } from '@/components/activity/activity-thread-hover-card-intent'
const COMMENT_MARKDOWN_CLASS_NAME =
'text-[11.5px] text-foreground break-words leading-normal [&_.comment-md-p]:block [&_.comment-md-p+.comment-md-p]:mt-1'
@@ -103,6 +104,12 @@ export function WorktreeCardDetailsHover({
},
[handleHoverOpenChange, workspaceTitleEditing]
)
// Same rest-to-peek intent as agent activity rows so passing pointers don't flash the card.
const hoverIntent = useActivityThreadHoverCardIntent({
open: hoverOpen || workspaceTitleEditing,
onOpenChange: handleEffectiveHoverOpenChange,
openDelay
})
const dismissAndRun = React.useCallback(
(handler: ((event: React.MouseEvent) => void) | undefined) => (event: React.MouseEvent) => {
closeHover()
@@ -143,8 +150,8 @@ export function WorktreeCardDetailsHover({
return (
<HoverCard
open={workspaceTitleEditing || (!contextMenuOpen && hoverOpen)}
onOpenChange={handleEffectiveHoverOpenChange}
openDelay={openDelay}
onOpenChange={hoverIntent.onOpenChange}
openDelay={0}
closeDelay={closeDelay}
>
<span className="contents" onClick={(event) => event.stopPropagation()}>
@@ -152,7 +159,13 @@ export function WorktreeCardDetailsHover({
</span>
<HoverCardTrigger
asChild
onPointerEnter={hasComment(comment) ? preloadCommentMarkdown : undefined}
{...hoverIntent.triggerHandlers}
onPointerEnter={(event) => {
hoverIntent.triggerHandlers.onPointerEnter(event)
if (hasComment(comment)) {
preloadCommentMarkdown()
}
}}
>
{children}
</HoverCardTrigger>
@@ -1,6 +1,6 @@
import type React from 'react'
export type LineageToggleHandler = (event: React.MouseEvent<HTMLButtonElement>) => void
export type LineageToggleHandler = (event: React.MouseEvent<HTMLElement>) => void
// Cache one handler per lineage group so callback identity cannot defeat WorktreeCard memoization.
export const createLineageToggleHandlerCache = (
@@ -8,14 +8,16 @@ import {
export function getWorktreeCardFrameGeometry({
flushSurface,
contentIndent,
statusLane
statusLane,
minContentInset
}: {
flushSurface: boolean
contentIndent: number
statusLane: boolean
minContentInset?: number
}): { cardStyle: React.CSSProperties | undefined; parentContentMarginLeft: number } {
const cardPaddingLeft = flushSurface
? getFlushWorktreeCardPaddingLeft(contentIndent, statusLane)
? getFlushWorktreeCardPaddingLeft(contentIndent, statusLane, minContentInset)
: contentIndent > 0
? `calc(0.125rem + ${contentIndent}px)`
: null
@@ -12,6 +12,7 @@ import type { WorktreeCardController } from '../controller/use-worktree-card-con
import { useWorktreeCardOpen } from './worktree-card-open-state'
import {
getLineageChildrenInlineStyle,
SLOT_CARD_MIN_CONTENT_INSET,
SLOT_LINEAGE_TITLE_COLUMN_SHIFT
} from '../../worktree-list/rows/indentation'
import { DEFAULT_WORKSPACE_CARD_TEMPLATE } from '../template/default-workspace-card'
@@ -66,7 +67,12 @@ export function WorktreeCardSurface({ card }: { card: WorktreeCardController }):
const isSleeping = useIsSleepingWorktree(worktree.id)
const cardOpen = useWorktreeCardOpen(worktree, card.lineageDescendantIdentities, slotLayout)
const geometryFor = (statusLane: boolean) =>
getWorktreeCardFrameGeometry({ flushSurface, contentIndent, statusLane })
getWorktreeCardFrameGeometry({
flushSurface,
contentIndent,
statusLane,
minContentInset: slotLayout ? SLOT_CARD_MIN_CONTENT_INSET : undefined
})
const { content: templateContent, frame } = renderWorkspaceCardTemplate(
card,
DEFAULT_WORKSPACE_CARD_TEMPLATE,
@@ -95,7 +101,7 @@ export function WorktreeCardSurface({ card }: { card: WorktreeCardController }):
className={cn(
'relative flex cursor-pointer flex-col transition-[background-color,border-color,opacity,box-shadow] duration-200 outline-none select-none',
'pr-1.5',
titleOnlyCard ? 'py-2' : 'pt-1.25 pb-1.5',
titleOnlyCard ? 'py-2' : slotLayout ? 'pt-2 pb-1.5' : 'pt-1.25 pb-1.5',
flushSurface ? 'ml-1 w-[calc(100%-0.25rem)]' : 'ml-1',
'overflow-hidden rounded-lg',
// Navigation updates the live attribute before React; it must own the complete active style.
@@ -7,6 +7,8 @@ export const FLUSH_CARD_CONTENT_PULLBACK = 4
export const NEW_CARD_STYLE_STATUS_LANE_EXTRA_PULLBACK = 8
// Why: keeps a zero-indent flush card off the sidebar edge.
export const FLUSH_CARD_MIN_CONTENT_INSET = 2
// Why: 2.0 nested cards have no indent, so their content needs its own breathing room off the card edge.
export const SLOT_CARD_MIN_CONTENT_INSET = 6
export const WORKTREE_CARD_SURFACE_MARGIN = 4
// Why: level-1 lineage keeps the grouped-card anchor; deeper levels advance evenly, not cumulatively.
export const LINEAGE_IMMEDIATE_PARENT_STEP =
@@ -134,14 +136,15 @@ export function getWorktreeCardSurfaceInset(args: {
export function getFlushWorktreeCardPaddingLeft(
contentIndent: number,
applyNewCardStyleStatusLaneOffset = false
applyNewCardStyleStatusLaneOffset = false,
minContentInset = FLUSH_CARD_MIN_CONTENT_INSET
): string {
const pullback =
FLUSH_CARD_CONTENT_PULLBACK +
(applyNewCardStyleStatusLaneOffset ? NEW_CARD_STYLE_STATUS_LANE_EXTRA_PULLBACK : 0)
return contentIndent > 0
? `max(${FLUSH_CARD_MIN_CONTENT_INSET}px, calc(${contentIndent}px - ${pullback}px))`
: `${FLUSH_CARD_MIN_CONTENT_INSET}px`
? `max(${minContentInset}px, calc(${contentIndent}px - ${pullback}px))`
: `${minContentInset}px`
}
export function getNewCardStyleParentContentMarginLeft(contentIndent: number): number {