Skip to content

Commit c944e18

Browse files
authored
Open diff files in the code viewer (#41)
- Route diff-file clicks through the in-app code viewer - Update diff file title text to match the new behavior - Bump package versions in lockfile
1 parent 29ccdb8 commit c944e18

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

apps/web/src/components/DiffPanel.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import { useNavigate, useParams, useSearch } from "@tanstack/react-router";
55
import { ThreadId, type TurnId } from "@okcode/contracts";
66
import { CheckIcon, ChevronDownIcon, Columns2Icon, Rows3Icon, TextWrapIcon } from "lucide-react";
77
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8-
import { openInPreferredEditor } from "../editorPreferences";
98
import { gitBranchesQueryOptions } from "~/lib/gitReactQuery";
109
import { checkpointDiffQueryOptions } from "~/lib/providerReactQuery";
1110
import { cn } from "~/lib/utils";
12-
import { readNativeApi } from "../nativeApi";
13-
import { resolvePathLinkTarget } from "../terminal-links";
11+
import { useCodeViewerStore } from "../codeViewerStore";
1412
import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch";
1513
import { useTheme } from "../hooks/useTheme";
1614
import { buildPatchCacheKey } from "../lib/diffRendering";
@@ -220,7 +218,7 @@ function DiffFileSection(props: {
220218
type="button"
221219
className="min-w-0 flex-1 truncate text-left font-mono text-[11px] text-foreground/90 underline-offset-2 hover:underline"
222220
onClick={() => onOpenInEditor(filePath)}
223-
title={`Open ${filePath} in editor`}
221+
title={`Open ${filePath}`}
224222
>
225223
{filePath}
226224
</button>
@@ -476,16 +474,13 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
476474
target?.scrollIntoView({ block: "nearest" });
477475
}, [selectedFilePath, renderableFiles]);
478476

479-
const openDiffFileInEditor = useCallback(
477+
const openFileInCodeViewer = useCodeViewerStore((state) => state.openFile);
478+
const openDiffFileInCodeViewer = useCallback(
480479
(filePath: string) => {
481-
const api = readNativeApi();
482-
if (!api) return;
483-
const targetPath = activeCwd ? resolvePathLinkTarget(filePath, activeCwd) : filePath;
484-
void openInPreferredEditor(api, targetPath).catch((error) => {
485-
console.warn("Failed to open diff file in editor.", error);
486-
});
480+
if (!activeCwd) return;
481+
openFileInCodeViewer(activeCwd, filePath);
487482
},
488-
[activeCwd],
483+
[activeCwd, openFileInCodeViewer],
489484
);
490485
const updateActiveReviewState = useCallback(
491486
(updater: (current: DiffFileReviewStateByPath) => DiffFileReviewStateByPath) => {
@@ -687,7 +682,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
687682
fileDiff={fileDiff}
688683
fileKey={themedFileKey}
689684
filePath={filePath}
690-
onOpenInEditor={openDiffFileInEditor}
685+
onOpenInEditor={openDiffFileInCodeViewer}
691686
onToggleAccepted={onToggleFileAccepted}
692687
onToggleCollapsed={onToggleFileCollapsed}
693688
resolvedTheme={resolvedTheme}

0 commit comments

Comments
 (0)