@@ -1961,6 +1961,16 @@ export default function ChatView(props: ChatViewProps) {
19611961 selectActiveRightPanel ( state . byThreadKey , activeThreadRef ) ,
19621962 ) ;
19631963 const diffOpen = activeRightPanelKind === "diff" ;
1964+ const explicitDiffOpenRef = useRef < ScopedThreadRef | null > ( null ) ;
1965+ useLayoutEffect ( ( ) => {
1966+ const explicitThreadRef = explicitDiffOpenRef . current ;
1967+ explicitDiffOpenRef . current = null ;
1968+ // Generic openings always show the checkout, including tab fallbacks and thread changes.
1969+ // A timeline click instead opens the specific turn/file the user requested.
1970+ if ( diffOpen && activeThreadRef && explicitThreadRef !== activeThreadRef ) {
1971+ useDiffPanelStore . getState ( ) . selectGitScope ( activeThreadRef , "unstaged" ) ;
1972+ }
1973+ } , [ activeThreadRef , diffOpen ] ) ;
19641974 const rightPanelState = useRightPanelStore ( ( state ) =>
19651975 selectThreadRightPanelState ( state . byThreadKey , activeThreadRef ) ,
19661976 ) ;
@@ -3712,9 +3722,6 @@ export default function ChatView(props: ChatViewProps) {
37123722 showEnvironmentIndicator : showComposerEnvironmentIndicator ,
37133723 hostsRestingComposerControls : routeKind === "server" && restingComposerControlsVisible ,
37143724 } ) ;
3715- const initialDiffPanelGitScope =
3716- gitStatusQuery . data ?. hasWorkingTreeChanges === true ? "unstaged" : "branch" ;
3717- const diffPanelGitStatusResolutionKey = gitStatusQuery . data ? "resolved" : "pending" ;
37183725 const terminalShortcutLabelOptions = useMemo (
37193726 ( ) => ( {
37203727 context : {
@@ -4501,6 +4508,7 @@ export default function ChatView(props: ChatViewProps) {
45014508 ) ;
45024509 const addDiffSurface = useCallback ( ( ) => {
45034510 if ( ! activeThreadRef || ! isServerThread || ! isGitRepo ) return ;
4511+ useDiffPanelStore . getState ( ) . selectGitScope ( activeThreadRef , "unstaged" ) ;
45044512 useRightPanelStore . getState ( ) . open ( activeThreadRef , "diff" ) ;
45054513 onDiffPanelOpen ?.( ) ;
45064514 } , [ activeThreadRef , isGitRepo , isServerThread , onDiffPanelOpen ] ) ;
@@ -4769,7 +4777,7 @@ export default function ChatView(props: ChatViewProps) {
47694777 if ( ! panels . openProactive ( activeThreadRef , { id : "diff" , kind : "diff" } , userActionRevision ) ) {
47704778 return ;
47714779 }
4772- useDiffPanelStore . getState ( ) . selectTurn ( activeThreadRef , newlyCompletedTurnId ) ;
4780+ useDiffPanelStore . getState ( ) . selectGitScope ( activeThreadRef , "unstaged" ) ;
47734781 onDiffPanelOpen ?.( ) ;
47744782 } , [
47754783 activeThread ?. checkpoints ,
@@ -9061,11 +9069,12 @@ export default function ChatView(props: ChatViewProps) {
90619069 const onOpenTurnDiff = useCallback (
90629070 ( turnId : TurnId , filePath ?: string ) => {
90639071 if ( ! isServerThread || ! activeThreadRef ) return ;
9072+ explicitDiffOpenRef . current = diffOpen ? null : activeThreadRef ;
90649073 useDiffPanelStore . getState ( ) . selectTurn ( activeThreadRef , turnId , filePath ) ;
90659074 useRightPanelStore . getState ( ) . open ( activeThreadRef , "diff" ) ;
90669075 onDiffPanelOpen ?.( ) ;
90679076 } ,
9068- [ activeThreadRef , isServerThread , onDiffPanelOpen ] ,
9077+ [ activeThreadRef , diffOpen , isServerThread , onDiffPanelOpen ] ,
90699078 ) ;
90709079 // The revert handler is read from a ref at call-time so the callback
90719080 // reference is fully stable and never busts TimelineRowCtx identity.
@@ -9209,10 +9218,9 @@ export default function ChatView(props: ChatViewProps) {
92099218 ) : renderedRightPanelSurface ?. kind === "diff" ? (
92109219 < Suspense fallback = { null } >
92119220 < DiffPanel
9212- key = { ` ${ activeThreadKey } : ${ diffPanelGitStatusResolutionKey } ` }
9221+ key = { activeThreadKey }
92139222 mode = "embedded"
92149223 composerDraftTarget = { composerDraftTarget }
9215- initialGitScope = { initialDiffPanelGitScope }
92169224 workspaceMutationId = { workspaceMutationId }
92179225 />
92189226 </ Suspense >
0 commit comments