critique 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/cli.tsx +63 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 0.0.12
|
|
2
|
+
|
|
3
|
+
- Default command:
|
|
4
|
+
- Show one file at a time with navigation arrows (← filename →)
|
|
5
|
+
- Use left/right arrow keys to navigate between files
|
|
6
|
+
- Persist current file selection in zustand state across watch refreshes
|
|
7
|
+
- Files are sorted by diff size (smallest first)
|
|
8
|
+
|
|
1
9
|
# 0.0.11
|
|
2
10
|
|
|
3
11
|
- Dependencies:
|
package/package.json
CHANGED
package/src/cli.tsx
CHANGED
|
@@ -62,6 +62,14 @@ class ScrollAcceleration {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
interface DiffState {
|
|
66
|
+
currentFileIndex: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const useDiffStore = create<DiffState>(() => ({
|
|
70
|
+
currentFileIndex: 0,
|
|
71
|
+
}));
|
|
72
|
+
|
|
65
73
|
interface AppProps {
|
|
66
74
|
parsedFiles: Array<{
|
|
67
75
|
oldFileName?: string;
|
|
@@ -74,6 +82,7 @@ function App({ parsedFiles }: AppProps) {
|
|
|
74
82
|
const { width: initialWidth } = useTerminalDimensions();
|
|
75
83
|
const [width, setWidth] = React.useState(initialWidth);
|
|
76
84
|
const [scrollAcceleration] = React.useState(() => new ScrollAcceleration());
|
|
85
|
+
const currentFileIndex = useDiffStore((s) => s.currentFileIndex);
|
|
77
86
|
|
|
78
87
|
useOnResize(
|
|
79
88
|
React.useCallback((newWidth: number) => {
|
|
@@ -96,15 +105,48 @@ function App({ parsedFiles }: AppProps) {
|
|
|
96
105
|
scrollAcceleration.multiplier = 10;
|
|
97
106
|
}
|
|
98
107
|
}
|
|
108
|
+
if (key.name === "left") {
|
|
109
|
+
useDiffStore.setState((state) => ({
|
|
110
|
+
currentFileIndex: Math.max(0, state.currentFileIndex - 1),
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
if (key.name === "right") {
|
|
114
|
+
useDiffStore.setState((state) => ({
|
|
115
|
+
currentFileIndex: Math.min(parsedFiles.length - 1, state.currentFileIndex + 1),
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
99
118
|
});
|
|
100
119
|
|
|
101
120
|
const { FileEditPreviewTitle, FileEditPreview } = require("./diff.tsx");
|
|
102
121
|
|
|
122
|
+
// Ensure current index is valid
|
|
123
|
+
const validIndex = Math.min(currentFileIndex, parsedFiles.length - 1);
|
|
124
|
+
const currentFile = parsedFiles[validIndex];
|
|
125
|
+
|
|
126
|
+
if (!currentFile) {
|
|
127
|
+
return (
|
|
128
|
+
<box style={{ padding: 1 }}>
|
|
129
|
+
<text>No files to display</text>
|
|
130
|
+
</box>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const fileName = currentFile.newFileName || currentFile.oldFileName || "unknown";
|
|
135
|
+
|
|
103
136
|
return (
|
|
104
137
|
<box
|
|
105
138
|
key={String(useSplitView)}
|
|
106
139
|
style={{ flexDirection: "column", height: "100%", padding: 1 }}
|
|
107
140
|
>
|
|
141
|
+
{/* Navigation header */}
|
|
142
|
+
<box style={{ marginBottom: 1, justifyContent: "center", alignItems: "center" }}>
|
|
143
|
+
<text fg={validIndex > 0 ? "#ffffff" : "#666666"}>←</text>
|
|
144
|
+
<text style={{ marginLeft: 2, marginRight: 2 }}>
|
|
145
|
+
{fileName} ({validIndex + 1}/{parsedFiles.length})
|
|
146
|
+
</text>
|
|
147
|
+
<text fg={validIndex < parsedFiles.length - 1 ? "#ffffff" : "#666666"}>→</text>
|
|
148
|
+
</box>
|
|
149
|
+
|
|
108
150
|
<scrollbox
|
|
109
151
|
scrollAcceleration={scrollAcceleration}
|
|
110
152
|
style={{
|
|
@@ -124,27 +166,17 @@ function App({ parsedFiles }: AppProps) {
|
|
|
124
166
|
focused
|
|
125
167
|
>
|
|
126
168
|
<box style={{ flexDirection: "column" }}>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
/>
|
|
139
|
-
<box paddingTop={1} />
|
|
140
|
-
<FileEditPreview
|
|
141
|
-
hunks={file.hunks}
|
|
142
|
-
paddingLeft={0}
|
|
143
|
-
splitView={useSplitView}
|
|
144
|
-
filePath={file.newFileName || file.oldFileName || ""}
|
|
145
|
-
/>
|
|
146
|
-
</box>
|
|
147
|
-
))}
|
|
169
|
+
<FileEditPreviewTitle
|
|
170
|
+
filePath={fileName}
|
|
171
|
+
hunks={currentFile.hunks}
|
|
172
|
+
/>
|
|
173
|
+
<box paddingTop={1} />
|
|
174
|
+
<FileEditPreview
|
|
175
|
+
hunks={currentFile.hunks}
|
|
176
|
+
paddingLeft={0}
|
|
177
|
+
splitView={useSplitView}
|
|
178
|
+
filePath={fileName}
|
|
179
|
+
/>
|
|
148
180
|
</box>
|
|
149
181
|
</scrollbox>
|
|
150
182
|
</box>
|
|
@@ -257,6 +289,16 @@ cli
|
|
|
257
289
|
};
|
|
258
290
|
}, []);
|
|
259
291
|
|
|
292
|
+
// Ensure currentFileIndex stays valid when files change
|
|
293
|
+
React.useEffect(() => {
|
|
294
|
+
if (parsedFiles && parsedFiles.length > 0) {
|
|
295
|
+
const currentIndex = useDiffStore.getState().currentFileIndex;
|
|
296
|
+
if (currentIndex >= parsedFiles.length) {
|
|
297
|
+
useDiffStore.setState({ currentFileIndex: parsedFiles.length - 1 });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}, [parsedFiles]);
|
|
301
|
+
|
|
260
302
|
if (parsedFiles === null) {
|
|
261
303
|
return (
|
|
262
304
|
<box style={{ padding: 1 }}>
|