@@ -26,7 +26,7 @@ import * as Schema from "effect/Schema";
2626import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
2727import { useOpenInPreferredEditor } from "../editorPreferences" ;
2828import { type DraftId } from "../composerDraftStore" ;
29- import { openDiffFilePrimaryAction } from "../diffFileActions" ;
29+ import { openDiffFileInEditor , openDiffFilePrimaryAction } from "../diffFileActions" ;
3030import { useCheckpointDiff } from "~/lib/checkpointDiffState" ;
3131import { cn } from "~/lib/utils" ;
3232import { selectThreadDiffPanelSelection , useDiffPanelStore } from "../diffPanelStore" ;
@@ -49,6 +49,7 @@ import { useProject, useThread } from "../state/entities";
4949import { resolveThreadRouteRef } from "../threadRoutes" ;
5050import { useClientSettings , useUpdateClientSettings } from "../hooks/useSettings" ;
5151import { formatShortTimestamp } from "../timestampFormat" ;
52+ import { DiffFileOpenInEditorButton } from "./DiffFileOpenInEditorButton" ;
5253import { DiffFilePathCopyButton } from "./DiffFilePathCopyButton" ;
5354import { DiffPanelLoadingState , DiffPanelShell , type DiffPanelMode } from "./DiffPanelShell" ;
5455import { DiffStatLabel } from "./chat/DiffStatLabel" ;
@@ -475,34 +476,51 @@ export default function DiffPanel({
475476 [ codeViewFiles , collapseScopeKey ] ,
476477 ) ;
477478
479+ const launchDiffFileInEditor = useCallback (
480+ ( targetPath : string ) => {
481+ void ( async ( ) => {
482+ const result = await openInPreferredEditor ( targetPath ) ;
483+ if ( result . _tag === "Failure" && ! isAtomCommandInterrupted ( result ) ) {
484+ console . warn ( "Failed to open diff file in editor." , {
485+ operation : "open-diff-file" ,
486+ ...( routeThreadRef
487+ ? {
488+ environmentId : routeThreadRef . environmentId ,
489+ threadId : routeThreadRef . threadId ,
490+ }
491+ : { } ) ,
492+ ...safeErrorLogAttributes ( squashAtomCommandFailure ( result ) ) ,
493+ } ) ;
494+ }
495+ } ) ( ) ;
496+ } ,
497+ [ openInPreferredEditor , routeThreadRef ] ,
498+ ) ;
478499 const openDiffFile = useCallback (
479500 ( filePath : string ) => {
480501 openDiffFilePrimaryAction ( {
481502 threadRef : routeThreadRef ,
482503 filePath,
483504 activeCwd,
484505 repositoryRoot : activeRepositoryRoot ,
485- openInEditor : ( targetPath ) => {
486- void ( async ( ) => {
487- const result = await openInPreferredEditor ( targetPath ) ;
488- if ( result . _tag === "Failure" && ! isAtomCommandInterrupted ( result ) ) {
489- console . warn ( "Failed to open diff file in editor." , {
490- operation : "open-diff-file" ,
491- ...( routeThreadRef
492- ? {
493- environmentId : routeThreadRef . environmentId ,
494- threadId : routeThreadRef . threadId ,
495- }
496- : { } ) ,
497- ...safeErrorLogAttributes ( squashAtomCommandFailure ( result ) ) ,
498- } ) ;
499- }
500- } ) ( ) ;
501- } ,
506+ openInEditor : launchDiffFileInEditor ,
507+ } ) ;
508+ } ,
509+ [ activeCwd , activeRepositoryRoot , launchDiffFileInEditor , routeThreadRef ] ,
510+ ) ;
511+ const openDiffFileExternally = useCallback (
512+ ( filePath : string ) => {
513+ openDiffFileInEditor ( {
514+ filePath,
515+ activeCwd,
516+ repositoryRoot : activeRepositoryRoot ,
517+ openInEditor : launchDiffFileInEditor ,
502518 } ) ;
503519 } ,
504- [ activeCwd , activeRepositoryRoot , openInPreferredEditor , routeThreadRef ] ,
520+ [ activeCwd , activeRepositoryRoot , launchDiffFileInEditor ] ,
505521 ) ;
522+ const canOpenDiffFileExternally =
523+ activeCwd != null && activeThread != null && ( serverConfig ?. availableEditors . length ?? 0 ) > 0 ;
506524 const toggleDiffFileCollapsed = useCallback (
507525 ( fileKey : string ) => {
508526 setCollapsedDiffFiles ( ( current ) => {
@@ -951,7 +969,8 @@ export default function DiffPanel({
951969 node instanceof HTMLElement && node . hasAttribute ( "data-title" ) ,
952970 ) ;
953971 const filePath = title ?. textContent ?. trim ( ) ;
954- // The filename remains the explicit "open in editor" affordance.
972+ // The filename is the internal file-viewer affordance. Header buttons keep
973+ // external actions separate and return above before reaching this handler.
955974 if ( filePath ) {
956975 openDiffFile ( filePath ) ;
957976 return ;
@@ -979,9 +998,19 @@ export default function DiffPanel({
979998 sectionId = { reviewSectionId }
980999 sectionTitle = { reviewSectionTitle }
9811000 composerDraftTarget = { composerDraftTarget }
982- renderHeaderFilenameSuffix = { ( fileDiff ) => (
983- < DiffFilePathCopyButton filePath = { resolveFileDiffPath ( fileDiff ) } />
984- ) }
1001+ renderHeaderFilenameSuffix = { ( fileDiff ) => {
1002+ const filePath = resolveFileDiffPath ( fileDiff ) ;
1003+ return (
1004+ < span className = "inline-flex items-center gap-0.5" >
1005+ < DiffFilePathCopyButton filePath = { filePath } />
1006+ < DiffFileOpenInEditorButton
1007+ filePath = { filePath }
1008+ disabled = { ! canOpenDiffFileExternally }
1009+ onOpen = { openDiffFileExternally }
1010+ />
1011+ </ span >
1012+ ) ;
1013+ } }
9851014 renderHeaderPrefix = { ( fileDiff , fileKey , collapsed ) => {
9861015 const filePath = resolveFileDiffPath ( fileDiff ) ;
9871016 return (
0 commit comments