Skip to content

Commit 28d943c

Browse files
committed
refactor: simplify git diff status icons
1 parent 19880e4 commit 28d943c

5 files changed

Lines changed: 73 additions & 97 deletions

File tree

‎package-lock.json‎

Lines changed: 1 addition & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"prismjs": "^1.30.0",
1818
"react": "^19.1.0",
1919
"react-dom": "^19.1.0",
20-
"react-file-icon": "^1.6.0",
2120
"react-markdown": "^10.1.0",
2221
"remark-gfm": "^4.0.1"
2322
},

‎src/components/GitDiffPanel.tsx‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FileIcon, defaultStyles } from "react-file-icon";
21
import type { GitLogEntry } from "../types";
32
import type { MouseEvent as ReactMouseEvent } from "react";
43
import { Menu, MenuItem } from "@tauri-apps/api/menu";
@@ -48,6 +47,40 @@ function splitNameAndExtension(name: string) {
4847
};
4948
}
5049

50+
function getStatusSymbol(status: string) {
51+
switch (status) {
52+
case "A":
53+
return "+";
54+
case "M":
55+
return "M";
56+
case "D":
57+
return "-";
58+
case "R":
59+
return "R";
60+
case "T":
61+
return "T";
62+
default:
63+
return "?";
64+
}
65+
}
66+
67+
function getStatusClass(status: string) {
68+
switch (status) {
69+
case "A":
70+
return "diff-icon-added";
71+
case "M":
72+
return "diff-icon-modified";
73+
case "D":
74+
return "diff-icon-deleted";
75+
case "R":
76+
return "diff-icon-renamed";
77+
case "T":
78+
return "diff-icon-typechange";
79+
default:
80+
return "diff-icon-unknown";
81+
}
82+
}
83+
5184
export function GitDiffPanel({
5285
mode,
5386
onModeChange,
@@ -153,8 +186,9 @@ export function GitDiffPanel({
153186
{files.map((file) => {
154187
const { name } = splitPath(file.path);
155188
const { base, extension } = splitNameAndExtension(name);
156-
const style = extension ? defaultStyles[extension] : undefined;
157189
const isSelected = file.path === selectedPath;
190+
const statusSymbol = getStatusSymbol(file.status);
191+
const statusClass = getStatusClass(file.status);
158192
return (
159193
<div
160194
key={file.path}
@@ -169,8 +203,8 @@ export function GitDiffPanel({
169203
}
170204
}}
171205
>
172-
<span className="diff-icon" aria-hidden>
173-
<FileIcon extension={extension || "file"} {...style} />
206+
<span className={`diff-icon ${statusClass}`} aria-hidden>
207+
{statusSymbol}
174208
</span>
175209
<div className="diff-file">
176210
<div className="diff-path">

‎src/styles/diff.css‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
.diff-list {
7373
display: flex;
7474
flex-direction: column;
75-
gap: 6px;
75+
gap: 3px;
7676
overflow-y: auto;
7777
flex: 1;
7878
padding-right: 2px;
@@ -93,8 +93,8 @@
9393
.diff-row {
9494
display: flex;
9595
gap: 8px;
96-
align-items: flex-start;
97-
padding: 6px 6px;
96+
align-items: center;
97+
padding: 4px 6px;
9898
border-radius: 8px;
9999
cursor: pointer;
100100
}
@@ -109,15 +109,41 @@
109109
}
110110

111111
.diff-icon {
112-
width: 18px;
113-
height: 18px;
112+
width: 16px;
113+
height: 16px;
114114
display: grid;
115115
place-items: center;
116+
border-radius: 4px;
117+
font-size: 10px;
118+
font-weight: 700;
119+
border: 1px solid transparent;
120+
line-height: 1;
116121
}
117122

118-
.diff-icon svg {
119-
width: 16px;
120-
height: 16px;
123+
.diff-icon-added {
124+
color: #47d488;
125+
border-color: rgba(71, 212, 136, 0.4);
126+
background: rgba(71, 212, 136, 0.12);
127+
}
128+
129+
.diff-icon-modified {
130+
color: #f5c363;
131+
border-color: rgba(245, 195, 99, 0.4);
132+
background: rgba(245, 195, 99, 0.12);
133+
}
134+
135+
.diff-icon-deleted {
136+
color: #ff6b6b;
137+
border-color: rgba(255, 107, 107, 0.45);
138+
background: rgba(255, 107, 107, 0.12);
139+
}
140+
141+
.diff-icon-renamed,
142+
.diff-icon-typechange,
143+
.diff-icon-unknown {
144+
color: var(--text-faint);
145+
border-color: var(--border-subtle);
146+
background: var(--surface-control);
121147
}
122148

123149
.diff-file {

‎src/types/ambient.d.ts‎

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

0 commit comments

Comments
 (0)