diff --git a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts index 257250b024a..7f10e7912b4 100644 --- a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts +++ b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.test.ts @@ -12,9 +12,15 @@ vi.mock('@/lib/workspace/tabs/workspace-tab-commands', () => ({ import { handleGuestWindowCloseMessage } from './browser-page-window-close' import { BROWSER_GUEST_WINDOW_CLOSE_CHANNEL } from '../../../../../shared/browser-guest-window-close' -function seedTab(pageId: string, isPinned = false, siblingPageIds: string[] = []): void { +function seedTab( + pageId: string, + isPinned = false, + siblingPageIds: string[] = [], + browserAnnotationsByPageId: Record = {} +): void { storeState.value = { closeBrowserPage: closeBrowserPageMock, + browserAnnotationsByPageId, browserTabsByWorktree: { 'wt-1': [{ id: 'ws-1' }] }, browserPagesByWorkspace: { 'ws-1': [{ id: pageId }, ...siblingPageIds.map((id) => ({ id }))] }, unifiedTabsByWorktree: { @@ -40,6 +46,13 @@ describe('window.close() from a browser page', () => { expect(dispatchMock).not.toHaveBeenCalled() }) + it('never discards unsent notes', () => { + seedTab('page-n', false, [], { 'page-n': [{ id: 'note-1' }] }) + closeFrom('page-n', { back: false, forward: false }) + expect(dispatchMock).not.toHaveBeenCalled() + expect(closeBrowserPageMock).not.toHaveBeenCalled() + }) + it('closes only the calling page when its Orca tab holds other pages', () => { seedTab('page-e', false, ['page-sibling']) closeFrom('page-e', { back: false, forward: false }) diff --git a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts index 452f602c2b1..5b37f60164e 100644 --- a/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts +++ b/src/renderer/src/components/browser-pane/host-guest/browser-page-window-close.ts @@ -32,7 +32,8 @@ export function handleGuestWindowCloseMessage( const tab = (state.unifiedTabsByWorktree[owner.worktreeId] ?? []).find( (candidate) => candidate.contentType === 'browser' && candidate.entityId === owner.workspaceId ) - if (tab?.isPinned) { + // A script may not discard what the user pinned or left unsent; the page's notes are all it closes. + if (tab?.isPinned || (state.browserAnnotationsByPageId[pageId]?.length ?? 0) > 0) { return } pagesOpenedByPage.delete(pageId) diff --git a/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.test.tsx b/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.test.tsx index 34290b57abf..e749f5645d1 100644 --- a/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.test.tsx +++ b/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.test.tsx @@ -158,17 +158,20 @@ async function render(visible = true) { ) } -it('labels same-repo sections by worktree name and a detached section by its HEAD', async () => { +it('identifies same-repo cards by name and shows their branch when collapsed', async () => { const [onBranch, detached] = setup(2) useAppStore.setState({ worktreesByRepo: { repo: [onBranch!, { ...detached!, branch: '', head: 'abc1234def' }] } }) await render() - expect( - [...container.querySelectorAll('section button[aria-expanded]')].map( - (toggle) => toggle.textContent - ) - ).toEqual(['ChildChild 0feature-0', 'ChildChild 1Detached HEAD · abc1234']) + const toggles = [ + ...container.querySelectorAll('section button[aria-expanded]') + ] + expect(toggles.map((toggle) => toggle.textContent)).toEqual(['ChildChild 0', 'ChildChild 1']) + expect([...container.querySelectorAll('section')].map((section) => section.textContent)).toEqual([ + 'ChildChild 0feature-0', + 'ChildChild 1Detached HEAD · abc1234' + ]) }) function ScopedStatusObserver({ owner }: { owner: SourceControlScope }) { diff --git a/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.tsx b/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.tsx index b8424d28834..13cc391236b 100644 --- a/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.tsx +++ b/src/renderer/src/components/right-sidebar/FolderWorkspaceSourceControlPanel.tsx @@ -26,6 +26,8 @@ import { SourceControlScopeProvider, type SourceControlScope } from './source-control/panel/worktree-scope' +import { SourceControlHeaderOverflowMenu } from './source-control/panel/header-overflow-menu' +import { SourceControlHeaderActionsSlot } from './source-control/panel/header-actions-slot' import { useWorktreeGitStatusObservation } from './source-control/sync/use-worktree-git-status-observation' import { useSourceControlWatchConsumer } from '@/hooks/source-control-watch-consumers' import { useSectionOnScreen } from './source-control/panel/section-viewport-presence' @@ -112,6 +114,7 @@ const WorktreeSection = memo( : null ) const panel = useMemo(() => , []) + const [actionsSlot, setActionsSlot] = useState(null) const identity = getWorktreeGitIdentityDisplay(owner.worktree) return (
+ ) : null + } onToggle={() => setExpanded(!isExpanded)} onOpen={() => useAppStore.getState().setActiveWorktree(id, owner.executionHostId)} + actionsSlotRef={setActionsSlot} /> {isExpanded && (!connected ? ( @@ -154,9 +164,11 @@ const WorktreeSection = memo( // A read error renders the body's existing failure banner with Retry. )} diff --git a/src/renderer/src/components/right-sidebar/folder-worktree-section-header.fixture.tsx b/src/renderer/src/components/right-sidebar/folder-worktree-section-header.fixture.tsx index 9d82daa4d4a..d40e0025386 100644 --- a/src/renderer/src/components/right-sidebar/folder-worktree-section-header.fixture.tsx +++ b/src/renderer/src/components/right-sidebar/folder-worktree-section-header.fixture.tsx @@ -36,6 +36,7 @@ function Cards() { expanded onToggle={() => {}} onOpen={() => {}} + actionsSlotRef={() => {}} />
@@ -48,6 +49,7 @@ function Cards() { expanded onToggle={() => {}} onOpen={() => {}} + actionsSlotRef={() => {}} /> @@ -59,6 +61,7 @@ function Cards() { expanded={false} onToggle={() => {}} onOpen={() => {}} + actionsSlotRef={() => {}} /> @@ -82,6 +85,7 @@ export const narrow = defineFixture({ expanded={false} onToggle={() => {}} onOpen={() => {}} + actionsSlotRef={() => {}} /> diff --git a/src/renderer/src/components/right-sidebar/folder-worktree-section-header.tsx b/src/renderer/src/components/right-sidebar/folder-worktree-section-header.tsx index 6df52b72b5d..66641f4b678 100644 --- a/src/renderer/src/components/right-sidebar/folder-worktree-section-header.tsx +++ b/src/renderer/src/components/right-sidebar/folder-worktree-section-header.tsx @@ -15,8 +15,31 @@ type FolderWorktreeSectionHeaderProps = { behind?: number changeCount: number expanded: boolean + showBranchInHeader?: boolean + actions?: React.ReactNode onToggle: () => void onOpen: () => void + /** Receives the embedded panel's filter and overflow buttons while expanded. */ + actionsSlotRef: (element: HTMLDivElement | null) => void +} + +function AheadBehind({ ahead, behind }: { ahead?: number; behind?: number }): React.JSX.Element { + return ( + <> + {!!ahead && ( + + + {ahead} + + )} + {!!behind && ( + + + {behind} + + )} + + ) } export function FolderWorktreeSectionHeader({ @@ -27,86 +50,101 @@ export function FolderWorktreeSectionHeader({ behind, changeCount, expanded, + showBranchInHeader = !expanded, + actions, onToggle, - onOpen + onOpen, + actionsSlotRef }: FolderWorktreeSectionHeaderProps): React.JSX.Element { const t = useTranslate() const openLabel = t( 'auto.components.rightSidebar.FolderWorkspaceSourceControl.openWorktree', 'Open this worktree' ) + const showWorktreeName = !!worktreeName && worktreeName !== branch + // Expanded cards show the branch once, in the body's picker; collapsed cards have no body. + const showSummaryRow = showBranchInHeader && (!!branch || !!ahead || !!behind || changeCount > 0) return ( // Pinned within its own card, above the panel's sticky COMMITS dock.
- + + + + + {openLabel} + + + {expanded && ( + + + + )} +
+ {actions} +
+
+ {showSummaryRow && ( + + {branch && ( + + + + {branch} + )} - - {(branch || !!ahead || !!behind) && ( - - {branch && ( - - - {branch} - - )} - {!!ahead && ( - - - {ahead} - - )} - {!!behind && ( - - - {behind} + + {!expanded && } + {!expanded && changeCount > 0 && ( + + {t( + 'auto.components.rightSidebar.FolderWorkspaceSourceControl.changeCount', + '{{count}} changes', + { count: changeCount, defaultValue_one: '{{count}} change' } + )} )} - )} - - - - - - {openLabel} - + + )}
) } diff --git a/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx b/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx index e6b95041d57..00a38832642 100644 --- a/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx +++ b/src/renderer/src/components/right-sidebar/source-control/listing/section-header.tsx @@ -3,6 +3,7 @@ import { ChevronDown } from 'lucide-react' import { cn } from '@/lib/class-names' import { Button } from '@/components/ui/button' import { useTranslate } from '@/i18n/use-translate' +import { useSourceControlScope } from '../panel/worktree-scope' export function SectionHeader({ label, @@ -23,22 +24,27 @@ export function SectionHeader({ actions?: React.ReactNode }): React.JSX.Element { const t = useTranslate() + // Folder cards keep the gap above the first file equal to the one below the last. + const compact = useSourceControlScope() !== null // Share the rounded container so hover styling spans the whole row. return ( -
+
-
{actions}
+
+ {actions} +
) diff --git a/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx b/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx index c80dea85b36..6c77ceaf81a 100644 --- a/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx +++ b/src/renderer/src/components/right-sidebar/source-control/listing/uncommitted-sections.tsx @@ -14,6 +14,7 @@ import { import { ActionButton } from './action-button' import { SectionHeader } from './section-header' import { SourceControlSectionFileList } from './section-file-list' +import { useSourceControlScope } from '../panel/worktree-scope' import { getSourceControlSectionViewAction, type SourceControlDisplaySection, @@ -89,6 +90,7 @@ export function SourceControlUncommittedSections(props: { requestDiscardEntry: (entry: GitStatusEntry) => void diffCommentCountByPath: Map }): React.JSX.Element { + const embedded = useSourceControlScope() !== null const t = useTranslate() return ( <> @@ -176,35 +178,37 @@ export function SourceControlUncommittedSections(props: { } /> {!isCollapsed && ( - +
+ +
)}
) diff --git a/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts b/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts index 9888f31b182..9cc0b17c0d0 100644 --- a/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts +++ b/src/renderer/src/components/right-sidebar/source-control/listing/use-selection.ts @@ -190,7 +190,8 @@ export function useSourceControlSelection({ return } - const container = containerRef.current + const panel = containerRef.current + const container = panel?.closest('[data-source-control-worktree]') ?? panel const target = e.target if (!container || !(target instanceof Node) || container.contains(target)) { return diff --git a/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx b/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx index af4712d35a9..940a009f98c 100644 --- a/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx +++ b/src/renderer/src/components/right-sidebar/source-control/panel/branch-context-row.tsx @@ -103,6 +103,7 @@ export function SourceControlBranchContextRow({ headControl, manualReviewUrl, branchLineTotal, + reviewControl, onChangeBaseRef, onRetry }: { @@ -112,6 +113,7 @@ export function SourceControlBranchContextRow({ headControl?: React.ReactNode manualReviewUrl?: string | null branchLineTotal?: GitBranchLineTotal | null + reviewControl?: React.ReactNode onChangeBaseRef: () => void onRetry: () => void }): React.JSX.Element | null { @@ -124,8 +126,11 @@ export function SourceControlBranchContextRow({ return null } return ( -
- {headControl ?? } +
+ + {headControl ?? } + + {reviewControl}
) } @@ -159,7 +164,12 @@ export function SourceControlBranchContextRow({ onChangeBaseRef={onChangeBaseRef} changeBaseTitle={changeBaseTitle} leading={