Skip to content

Commit 751f3d6

Browse files
committed
Remove mode-aware diff comparison system
1 parent 3d8a30c commit 751f3d6

5 files changed

Lines changed: 9 additions & 100 deletions

File tree

apps/twig/src/renderer/features/code-editor/components/DiffEditorPanel.tsx

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { CodeMirrorEditor } from "@features/code-editor/components/CodeMirrorEdi
44
import { getRelativePath } from "@features/code-editor/utils/pathUtils";
55
import { usePanelLayoutStore } from "@features/panels/store/panelLayoutStore";
66
import { useCwd } from "@features/sidebar/hooks/useCwd";
7-
import { useChangesModeStore } from "@features/task-detail/stores/changesModeStore";
87
import { Box } from "@radix-ui/themes";
98
import { trpcVanilla } from "@renderer/trpc/client";
109
import type { Task } from "@shared/types";
@@ -29,21 +28,6 @@ export function DiffEditorPanel({
2928
(s) => s.closeDiffTabsForFile,
3029
);
3130

32-
// Comparison mode
33-
const compMode = useChangesModeStore((s) => s.mode);
34-
const isBranchMode = compMode === "branch";
35-
36-
// Fetch merge-base SHA when in branch mode
37-
const { data: mergeBase } = useQuery({
38-
queryKey: ["merge-base", repoPath],
39-
queryFn: () =>
40-
trpcVanilla.git.getMergeBase.query({
41-
directoryPath: repoPath as string,
42-
}),
43-
enabled: !!repoPath && isBranchMode,
44-
staleTime: 5_000,
45-
});
46-
4731
const { data: changedFiles = [], isLoading: loadingChangelist } = useQuery({
4832
queryKey: ["changed-files-head", repoPath],
4933
queryFn: () =>
@@ -75,24 +59,14 @@ export function DiffEditorPanel({
7559
refetchOnWindowFocus: true,
7660
});
7761

78-
// Original content: for branch mode use merge-base; otherwise HEAD
79-
const originalRef = isBranchMode && mergeBase ? mergeBase : "HEAD";
8062
const { data: originalContent, isLoading: loadingOriginal } = useQuery({
81-
queryKey: isBranchMode
82-
? ["file-at-ref", repoPath, originalPath, originalRef]
83-
: ["file-at-head", repoPath, originalPath],
63+
queryKey: ["file-at-head", repoPath, originalPath],
8464
queryFn: () =>
85-
isBranchMode
86-
? trpcVanilla.git.getFileAtRef.query({
87-
directoryPath: repoPath as string,
88-
filePath: originalPath,
89-
ref: originalRef,
90-
})
91-
: trpcVanilla.git.getFileAtHead.query({
92-
directoryPath: repoPath as string,
93-
filePath: originalPath,
94-
}),
95-
enabled: !!repoPath && !isNew && (!isBranchMode || !!mergeBase),
65+
trpcVanilla.git.getFileAtHead.query({
66+
directoryPath: repoPath as string,
67+
filePath: originalPath,
68+
}),
69+
enabled: !!repoPath && !isNew,
9670
staleTime: 30_000,
9771
refetchOnWindowFocus: true,
9872
});
@@ -103,13 +77,9 @@ export function DiffEditorPanel({
10377
queryKey: ["repo-file", repoPath, filePath],
10478
});
10579
queryClient.invalidateQueries({ queryKey: ["file-at-head", repoPath] });
106-
queryClient.invalidateQueries({ queryKey: ["file-at-ref", repoPath] });
10780
queryClient.invalidateQueries({
10881
queryKey: ["changed-files-head", repoPath],
10982
});
110-
queryClient.invalidateQueries({
111-
queryKey: ["changed-files-mode", repoPath],
112-
});
11383
}, [repoPath, filePath, queryClient]);
11484

11585
const handleContentChange = useCallback(
@@ -129,12 +99,6 @@ export function DiffEditorPanel({
12999
queryClient.invalidateQueries({
130100
queryKey: ["changed-files-head", repoPath],
131101
});
132-
queryClient.invalidateQueries({
133-
queryKey: ["changed-files-mode", repoPath],
134-
});
135-
queryClient.invalidateQueries({
136-
queryKey: ["diff-stats-mode", repoPath],
137-
});
138102
} catch (_error) {}
139103
},
140104
[repoPath, filePath, queryClient],
@@ -172,9 +136,6 @@ export function DiffEditorPanel({
172136
const showDiff = !isDeleted && !isNew;
173137
const content = isDeleted ? originalContent : modifiedContent;
174138

175-
// Don't allow content editing in branch mode
176-
const allowContentChange = !isBranchMode;
177-
178139
return (
179140
<Box height="100%" style={{ overflow: "hidden" }}>
180141
{showDiff ? (
@@ -183,7 +144,7 @@ export function DiffEditorPanel({
183144
modifiedContent={modifiedContent ?? ""}
184145
filePath={absolutePath}
185146
relativePath={filePath}
186-
onContentChange={allowContentChange ? handleContentChange : undefined}
147+
onContentChange={handleContentChange}
187148
onRefresh={handleRefresh}
188149
/>
189150
) : (

apps/twig/src/renderer/features/message-editor/components/DiffStatsIndicator.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useChangesModeStore } from "@features/task-detail/stores/changesModeStore";
21
import { Circle } from "@phosphor-icons/react";
32
import { Flex, Text } from "@radix-ui/themes";
43
import { trpcVanilla } from "@renderer/trpc";
@@ -9,14 +8,11 @@ interface DiffStatsIndicatorProps {
98
}
109

1110
export function DiffStatsIndicator({ repoPath }: DiffStatsIndicatorProps) {
12-
const mode = useChangesModeStore((s) => s.mode);
13-
1411
const { data: diffStats } = useQuery({
15-
queryKey: ["diff-stats-mode", repoPath, mode],
12+
queryKey: ["diff-stats", repoPath],
1613
queryFn: () =>
17-
trpcVanilla.git.getDiffStatsByMode.query({
14+
trpcVanilla.git.getDiffStats.query({
1815
directoryPath: repoPath as string,
19-
mode: mode === "lastTurn" ? "uncommitted" : mode,
2016
}),
2117
enabled: !!repoPath,
2218
staleTime: 5000,

apps/twig/src/renderer/features/task-detail/stores/changesModeStore.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

apps/twig/src/renderer/hooks/useFileWatcher.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ export function useFileWatcher(repoPath: string | null, taskId?: string) {
3333
queryClient.invalidateQueries({
3434
queryKey: ["changed-files-head", repoPath],
3535
});
36-
queryClient.invalidateQueries({
37-
queryKey: ["changed-files-mode", repoPath],
38-
});
3936
queryClient.invalidateQueries({
4037
queryKey: ["diff-stats", repoPath],
4138
});
42-
queryClient.invalidateQueries({
43-
queryKey: ["diff-stats-mode", repoPath],
44-
});
4539
},
4640
});
4741

@@ -52,15 +46,9 @@ export function useFileWatcher(repoPath: string | null, taskId?: string) {
5246
queryClient.invalidateQueries({
5347
queryKey: ["changed-files-head", repoPath],
5448
});
55-
queryClient.invalidateQueries({
56-
queryKey: ["changed-files-mode", repoPath],
57-
});
5849
queryClient.invalidateQueries({
5950
queryKey: ["diff-stats", repoPath],
6051
});
61-
queryClient.invalidateQueries({
62-
queryKey: ["diff-stats-mode", repoPath],
63-
});
6452
if (!taskId) return;
6553
const relativePath = filePath.replace(`${repoPath}/`, "");
6654
closeTabsForFile(taskId, relativePath);
@@ -72,22 +60,12 @@ export function useFileWatcher(repoPath: string | null, taskId?: string) {
7260
onData: ({ repoPath: rp }) => {
7361
if (rp !== repoPath) return;
7462
queryClient.invalidateQueries({ queryKey: ["file-at-head", repoPath] });
75-
queryClient.invalidateQueries({ queryKey: ["file-at-ref", repoPath] });
7663
queryClient.invalidateQueries({
7764
queryKey: ["changed-files-head", repoPath],
7865
});
79-
queryClient.invalidateQueries({
80-
queryKey: ["changed-files-mode", repoPath],
81-
});
8266
queryClient.invalidateQueries({
8367
queryKey: ["diff-stats", repoPath],
8468
});
85-
queryClient.invalidateQueries({
86-
queryKey: ["diff-stats-mode", repoPath],
87-
});
88-
queryClient.invalidateQueries({
89-
queryKey: ["merge-base", repoPath],
90-
});
9169
queryClient.invalidateQueries({
9270
queryKey: ["git-sync-status", repoPath],
9371
});

apps/twig/src/renderer/stores/focusStore.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ interface FocusState {
2929
function invalidateQueries() {
3030
queryClient.invalidateQueries({ queryKey: ["current-branch"] });
3131
queryClient.invalidateQueries({ queryKey: ["diff-stats"] });
32-
queryClient.invalidateQueries({ queryKey: ["diff-stats-mode"] });
3332
queryClient.invalidateQueries({ queryKey: ["changed-files-head"] });
34-
queryClient.invalidateQueries({ queryKey: ["changed-files-mode"] });
3533
queryClient.invalidateQueries({ queryKey: ["git-sync-status"] });
3634
}
3735

0 commit comments

Comments
 (0)