diff --git a/src/renderer/src/components/editor/CombinedDiffViewer.tsx b/src/renderer/src/components/editor/CombinedDiffViewer.tsx
index 2c53bd87285..653130200f3 100644
--- a/src/renderer/src/components/editor/CombinedDiffViewer.tsx
+++ b/src/renderer/src/components/editor/CombinedDiffViewer.tsx
@@ -13,6 +13,8 @@ import { getVirtualizedScrollAnchorForOffset } from '@/hooks/virtualized-scroll-
import { createProgrammaticScrollMarks } from '@/hooks/programmatic-scroll-marks'
import { joinPath } from '@/lib/path'
import { detectLanguage } from '@/lib/language-detect'
+import { openFilePreviewToSide } from '@/lib/file-preview'
+import { canOpenDiffSectionPreviewToSide } from './diff-section-preview'
import { setWithLRU } from '@/lib/scroll-cache'
import { getCombinedDiffSectionConnectionId } from './combined-diff-section-connection'
import { findWorktreeById } from '@/store/slices/worktree-helpers'
@@ -1284,6 +1286,29 @@ export default function CombinedDiffViewer({
]
)
+ // Why: match single-file HTML diffs — preview the on-disk working tree file
+ // beside the combined view when the section is still present on disk.
+ const openSectionPreview = useCallback(
+ (section: DiffSection) => {
+ if (
+ !canOpenDiffSectionPreviewToSide({
+ path: section.path,
+ status: section.status,
+ isCommitSurface: isCommitMode
+ })
+ ) {
+ return
+ }
+ openFilePreviewToSide({
+ language: detectLanguage(section.path),
+ filePath: joinPath(file.filePath, section.path),
+ worktreeId: file.worktreeId,
+ sourceGroupId: activeGroupId ?? null
+ })
+ },
+ [activeGroupId, file.filePath, file.worktreeId, isCommitMode]
+ )
+
const handleSectionSave = useCallback(
async (index: number) => {
const section = sections[index]
@@ -2024,6 +2049,15 @@ export default function CombinedDiffViewer({
openSectionTitle={
isAllMode || isBranchMode || isCommitMode ? 'Open diff' : 'Open in editor'
}
+ onOpenPreview={
+ canOpenDiffSectionPreviewToSide({
+ path: section.path,
+ status: section.status,
+ isCommitSurface: isCommitMode
+ })
+ ? (previewSection) => openSectionPreview(previewSection)
+ : undefined
+ }
setSectionHeights={setSectionHeights}
setSections={setSections}
modifiedEditorsRef={modifiedEditorsRef}
diff --git a/src/renderer/src/components/editor/DiffSectionHeader.tsx b/src/renderer/src/components/editor/DiffSectionHeader.tsx
index 8df224e7c9d..e26d993baff 100644
--- a/src/renderer/src/components/editor/DiffSectionHeader.tsx
+++ b/src/renderer/src/components/editor/DiffSectionHeader.tsx
@@ -1,4 +1,4 @@
-import { ChevronDown, ChevronRight, ExternalLink } from 'lucide-react'
+import { ChevronDown, ChevronRight, ExternalLink, Eye } from 'lucide-react'
import type { MouseEvent, ReactElement, ReactNode } from 'react'
import { translate } from '@/i18n/i18n'
@@ -11,6 +11,7 @@ export function DiffSectionHeader({
onToggle,
onOpenSection,
openSectionTitle,
+ onOpenPreview,
trailingContent
}: {
path: string
@@ -21,6 +22,7 @@ export function DiffSectionHeader({
onToggle: () => void
onOpenSection: (event: MouseEvent) => void
openSectionTitle: string
+ onOpenPreview?: (event: MouseEvent) => void
trailingContent?: ReactNode
}): ReactElement {
return (
@@ -71,8 +73,29 @@ export function DiffSectionHeader({
{trailingContent}
+ {onOpenPreview != null && (
+
+ )}