Skip to content

Commit cfc0d70

Browse files
committed
fix: keep commit columns readable in large repos
In repositories with many concurrent branches (e.g. nixpkgs) the commit graph grew wider than the viewport, pushing the commit message off screen and breaking column alignment. - Cap the graph width to the space left after the message + right columns; lanes beyond the cap are clipped so the message and columns stay visible. - Clip the SHA column (overflow:hidden + ellipsis) so the long abbreviated hashes git uses in huge repos no longer spill into the date column. - Wrap the author name in a span so it truncates with an ellipsis instead of being hard-cut. - Left-align the date column. Fixes #17
1 parent d4ccce3 commit cfc0d70

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

webview-ui/src/components/graph/CommitGraph.svelte

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,21 @@
309309
let container: HTMLDivElement | undefined = $state();
310310
let scrollTop = $state(0);
311311
let viewportHeight = $state(600);
312+
let viewportWidth = $state(800);
313+
314+
// Right-side columns (author + sha + date) and the minimum width we always
315+
// reserve for the commit message. These mirror the fixed column widths in the
316+
// CSS below.
317+
const RIGHT_COLS_WIDTH = 120 + 75 + 160;
318+
const MIN_MESSAGE_WIDTH = 120;
319+
320+
// In huge repos (e.g. nixpkgs) hundreds of concurrent branches make the graph
321+
// grow wider than the whole viewport, which would push the commit message off
322+
// screen and break column alignment. Cap the graph at whatever space is left
323+
// after the message + right columns; lanes beyond the cap are clipped.
324+
let maxGraphWidth = $derived(
325+
Math.max(120, viewportWidth - RIGHT_COLS_WIDTH - MIN_MESSAGE_WIDTH)
326+
);
312327
313328
// Scroll to search result when navigating
314329
$effect(() => {
@@ -331,7 +346,7 @@
331346
if (displayLeftMargin.length > 0) {
332347
let maxMargin = 0;
333348
for (const m of displayLeftMargin) if (m > maxMargin) maxMargin = m;
334-
return Math.ceil(maxMargin * X_SCALE) + 4;
349+
return Math.min(Math.ceil(maxMargin * X_SCALE) + 4, maxGraphWidth);
335350
}
336351
return 30;
337352
});
@@ -404,6 +419,7 @@
404419
function handleResize() {
405420
if (container) {
406421
viewportHeight = container.clientHeight;
422+
viewportWidth = container.clientWidth;
407423
}
408424
}
409425
@@ -785,6 +801,7 @@
785801
$effect(() => {
786802
if (container) {
787803
viewportHeight = container.clientHeight;
804+
viewportWidth = container.clientWidth;
788805
}
789806
});
790807
</script>
@@ -821,7 +838,7 @@
821838
<svg
822839
class="graph-lines"
823840
width={graphWidth}
824-
style="position: absolute; top: 0; height: {totalHeight}px; overflow: visible;"
841+
style="position: absolute; top: 0; height: {totalHeight}px; overflow: hidden;"
825842
>
826843
<!-- Paths: continuous branch lines -->
827844
{#each visiblePaths as path}
@@ -958,7 +975,7 @@
958975
}
959976
}}
960977
>
961-
<div class="col-message" style="padding-left: {(displayLeftMargin[index] ?? graphWidth) * X_SCALE + 4}px;">
978+
<div class="col-message" style="padding-left: {Math.min((displayLeftMargin[index] ?? graphWidth) * X_SCALE + 4, maxGraphWidth)}px;">
962979
{#if currentBranchLocalOnly.has(commit.hash)}
963980
<span class="local-dot" use:tooltip={t('graph.notPushed')}></span>
964981
{:else if currentBranchRemoteAhead.has(commit.hash)}
@@ -1087,10 +1104,10 @@
10871104
<span class="commit-subject truncate" use:tooltip={commit.subject}>{commit.subject}</span>
10881105
{/if}
10891106
</div>
1090-
<div class="col-author truncate" use:tooltip={commit.author.name}>
1107+
<div class="col-author" use:tooltip={commit.author.name}>
10911108
{#if commit.hash !== 'UNCOMMITTED'}
10921109
<img class="avatar-sm" src={getGravatarUrl(commit.author.email, 20)} alt="" loading="lazy" />
1093-
{commit.author.name}
1110+
<span class="author-name truncate">{commit.author.name}</span>
10941111
{/if}
10951112
</div>
10961113
<div class="col-hash" use:tooltip={commit.hash !== 'UNCOMMITTED' ? commit.hash : ''}>{commit.hash !== 'UNCOMMITTED' ? commit.abbreviatedHash : ''}</div>
@@ -1462,6 +1479,11 @@
14621479
flex-shrink: 0;
14631480
}
14641481
1482+
/* Flex item must allow shrinking below content size for ellipsis to engage. */
1483+
.author-name {
1484+
min-width: 0;
1485+
}
1486+
14651487
.commit-row.selected .col-author,
14661488
.commit-row.selected .col-date,
14671489
.commit-row.selected .col-hash {
@@ -1475,7 +1497,7 @@
14751497
padding: 0 10px;
14761498
color: var(--text-secondary);
14771499
white-space: nowrap;
1478-
text-align: right;
1500+
text-align: left;
14791501
}
14801502
14811503
.col-hash {
@@ -1484,6 +1506,11 @@
14841506
padding: 0 10px;
14851507
font-family: var(--vscode-editor-font-family, monospace);
14861508
color: var(--text-secondary);
1509+
/* Large repos abbreviate hashes to 10-12 chars; clip so they never spill
1510+
into the date column. */
1511+
overflow: hidden;
1512+
text-overflow: ellipsis;
1513+
white-space: nowrap;
14871514
}
14881515
14891516
.commit-subject {

0 commit comments

Comments
 (0)