Skip to content

Commit 7a87389

Browse files
committed
Improve git panel responsiveness for narrow widths
1 parent f1129df commit 7a87389

File tree

1 file changed

+47
-35
lines changed

1 file changed

+47
-35
lines changed

src/renderer/components/git/GitTree.tsx

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const LANE_COLORS = [
1919
'#f87171',
2020
]
2121

22-
const COL_WIDTH = 16
23-
const ROW_HEIGHT = 36
24-
const NODE_RADIUS = 4
25-
const MERGE_RADIUS = 5
22+
const COL_WIDTH = 14
23+
const ROW_HEIGHT = 32
24+
const NODE_RADIUS = 3
25+
const MERGE_RADIUS = 4
2626

2727
interface GraphRow {
2828
commit: GitCommit
@@ -179,13 +179,18 @@ function GraphSvg({ rows }: { rows: GraphRow[] }): React.ReactElement {
179179

180180
function RefBadge({ label, index }: { label: string; index: number }): React.ReactElement {
181181
const isHead = label.startsWith('HEAD')
182+
const isTag = label.startsWith('tag:')
182183
const base = isHead
183184
? 'bg-red-500/20 text-red-400 border border-red-500/30'
185+
: isTag
186+
? 'bg-purple-500/15 text-purple-400 border border-purple-500/25'
184187
: 'bg-zinc-700/30 text-zinc-400 border border-zinc-600/40'
185188

189+
const displayLabel = label.startsWith('tag: ') ? label.slice(5) : label
190+
186191
return (
187-
<span className={`inline-flex items-center rounded px-1 py-px text-[10px] font-medium leading-tight ${base}`}>
188-
{label}
192+
<span className={`shrink-0 inline-flex items-center rounded px-1 py-px text-[9px] font-medium leading-tight max-w-[80px] truncate ${base}`}>
193+
{displayLabel}
189194
</span>
190195
)
191196
}
@@ -238,6 +243,11 @@ export function GitTree(): React.ReactElement {
238243
}, [activeProject?.id])
239244

240245
const graphRows = useMemo(() => (commits ? buildGraph(commits) : []), [commits])
246+
const graphWidth = useMemo(() => {
247+
if (graphRows.length === 0) return COL_WIDTH + 8
248+
const maxCols = Math.max(1, ...graphRows.map((r) => Math.max(r.col + 1, ...r.lines.map((l) => Math.max(l.fromCol, l.toCol) + 1))))
249+
return maxCols * COL_WIDTH + 12
250+
}, [graphRows])
241251
const currentBranch = branches?.find((b) => b.current)
242252
const isOnDefault = currentBranch && (currentBranch.name === 'main' || currentBranch.name === 'master')
243253

@@ -259,61 +269,60 @@ export function GitTree(): React.ReactElement {
259269

260270
return (
261271
<div className="relative flex h-full flex-col bg-zinc-950">
262-
<div className="flex items-center justify-between border-b border-zinc-800 bg-zinc-900/50 px-3 py-1.5">
263-
<div className="flex items-center gap-2">
264-
<GitBranchIcon size={14} className="text-zinc-500" />
265-
<span className="text-xs text-zinc-400">Git</span>
272+
<div className="flex items-center justify-between border-b border-zinc-800 bg-zinc-900/50 px-2 py-1">
273+
<div className="flex min-w-0 items-center gap-1.5">
274+
<GitBranchIcon size={13} className="shrink-0 text-zinc-500" />
275+
<span className="shrink-0 text-[11px] text-zinc-400">Git</span>
266276
{currentBranch && (
267-
<span className="rounded bg-green-400/15 px-1.5 py-0.5 text-[10px] font-medium text-green-400">
277+
<span className="truncate rounded bg-green-400/15 px-1.5 py-px text-[10px] font-medium text-green-400">
268278
{currentBranch.name}
269279
</span>
270280
)}
271281
{drift && drift.behind > 0 && !drift.diverged && activeProjectId && activeProject && (
272282
<button
273283
onClick={() => pullAction(activeProjectId, activeProject.path)}
274-
className="flex items-center gap-1 rounded bg-blue-500/15 px-1.5 py-0.5 text-[10px] font-medium text-blue-400 hover:bg-blue-500/25"
284+
className="flex shrink-0 items-center gap-0.5 rounded bg-blue-500/15 px-1 py-px text-[10px] font-medium text-blue-400 hover:bg-blue-500/25"
275285
title={`${drift.behind} commit${drift.behind > 1 ? 's' : ''} behind ${drift.remoteBranch ?? 'remote'} — click to pull`}
276286
>
277-
<ArrowDown size={10} />
287+
<ArrowDown size={9} />
278288
<span>{drift.behind}</span>
279289
</button>
280290
)}
281291
{drift?.diverged && activeProjectId && activeProject && (
282292
<button
283293
onClick={() => rebaseAction(activeProjectId, activeProject.path)}
284-
className="flex items-center gap-1 rounded bg-amber-500/15 px-1.5 py-0.5 text-[10px] font-medium text-amber-400 hover:bg-amber-500/25"
294+
className="flex shrink-0 items-center gap-0.5 rounded bg-amber-500/15 px-1 py-px text-[10px] font-medium text-amber-400 hover:bg-amber-500/25"
285295
title={`Diverged: ${drift.ahead} ahead, ${drift.behind} behind — click to rebase`}
286296
>
287-
<GitMerge size={10} />
297+
<GitMerge size={9} />
288298
<span>{drift.ahead}/{drift.behind}</span>
289299
</button>
290300
)}
291301
</div>
292-
<div className="flex items-center gap-1">
302+
<div className="flex shrink-0 items-center">
293303
<button
294304
disabled={!activeTerminalTabId}
295305
onClick={() => activeTerminalTabId && sendToTerminal(activeTerminalTabId, '/commit')}
296-
className="flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:pointer-events-none"
306+
className="rounded p-1 text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:pointer-events-none"
307+
title="Commit"
297308
>
298-
<GitCommitHorizontal size={12} />
299-
<span>Commit</span>
309+
<GitCommitHorizontal size={13} />
300310
</button>
301311
<button
302312
disabled={!activeTerminalTabId || !!isOnDefault}
303313
onClick={handleCreatePR}
304-
className="flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:pointer-events-none"
314+
className="rounded p-1 text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:pointer-events-none"
305315
title={isOnDefault ? 'Switch to a feature branch first' : 'Create pull request'}
306316
>
307-
<GitPullRequest size={12} />
308-
<span>PR</span>
317+
<GitPullRequest size={13} />
309318
</button>
310319
<button
311320
disabled={!activeTerminalTabId}
312321
onClick={() => setFeatureModalOpen(true)}
313-
className="flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:pointer-events-none"
322+
className="rounded p-1 text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:pointer-events-none"
323+
title="New Feature"
314324
>
315-
<Sparkles size={12} />
316-
<span>New Feature</span>
325+
<Sparkles size={13} />
317326
</button>
318327
<button
319328
onClick={() => activeProject && loadGitData(activeProject.id, activeProject.path)}
@@ -331,25 +340,28 @@ export function GitTree(): React.ReactElement {
331340
<GraphSvg rows={graphRows} />
332341
</div>
333342

334-
<div className="relative" style={{ marginLeft: Math.max(1, ...graphRows.map((r) => Math.max(r.col + 1, ...r.lines.map((l) => Math.max(l.fromCol, l.toCol) + 1)))) * COL_WIDTH + 12 }}>
343+
<div className="relative" style={{ marginLeft: graphWidth }}>
335344
{graphRows.map((row) => (
336345
<div
337346
key={row.commit.hash}
338-
className="flex items-center gap-2 pr-3 hover:bg-zinc-800/30"
347+
className="flex items-center pr-2 hover:bg-zinc-800/30"
339348
style={{ height: ROW_HEIGHT }}
340349
>
341-
<div className="min-w-0 flex-1">
342-
<div className="flex items-center gap-1.5">
350+
<div className="min-w-0 flex-1 overflow-hidden">
351+
<div className="flex items-center gap-1 overflow-hidden">
343352
{row.commit.refs.length > 0 &&
344-
row.commit.refs.map((ref, ri) => (
353+
row.commit.refs.slice(0, 2).map((ref, ri) => (
345354
<RefBadge key={ref} label={ref} index={ri} />
346355
))}
347-
<span className="truncate text-xs text-zinc-300">{row.commit.message}</span>
356+
{row.commit.refs.length > 2 && (
357+
<span className="shrink-0 text-[9px] text-zinc-500">+{row.commit.refs.length - 2}</span>
358+
)}
359+
<span className="truncate text-[11px] leading-tight text-zinc-300">{row.commit.message}</span>
348360
</div>
349-
<div className="flex items-center gap-2 text-[10px] text-zinc-400">
350-
<span className="font-mono">{row.commit.shortHash}</span>
351-
<span>{row.commit.author}</span>
352-
<span>{row.commit.date}</span>
361+
<div className="flex items-center gap-1.5 overflow-hidden text-[9px] text-zinc-500">
362+
<span className="shrink-0 font-mono">{row.commit.shortHash}</span>
363+
<span className="truncate">{row.commit.author}</span>
364+
<span className="shrink-0">{row.commit.date}</span>
353365
</div>
354366
</div>
355367
</div>

0 commit comments

Comments
 (0)