Skip to content

Commit b0ed0e8

Browse files
committed
fit to last 10 commits
1 parent 22931c0 commit b0ed0e8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

components/git-visualizer.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,20 @@ export function GitVisualizer({
264264
if (!cy) return;
265265
try {
266266
cy.resize();
267-
cy.fit(undefined, 30);
267+
// Fit to the last 5 commits (most recent). If fewer than 5, fit all.
268+
const recentIds = commits.slice(undefined, 10).map((c) => c.id);
269+
const recentNodes = recentIds.length > 0 ? cy.getElementById(recentIds[0]) : cy.collection();
270+
for (let i = 1; i < recentIds.length; i++) {
271+
recentNodes.merge(cy.getElementById(recentIds[i]));
272+
}
273+
cy.fit(recentNodes.nonempty() ? recentNodes : undefined, 30);
268274
} catch (error) {
269275
console.warn("Resize error:", error);
270276
}
271277
};
272278
window.addEventListener("resize", onResize);
273279
return () => window.removeEventListener("resize", onResize);
274-
}, []);
280+
}, [commits]);
275281

276282
// Re-run layout when commit set changes size to avoid race conditions during rapid branch switches
277283
const lastElementCountRef = useRef<number>(0);
@@ -295,7 +301,13 @@ export function GitVisualizer({
295301
l.run();
296302
// Fit with padding if still mounted
297303
if (cyRef.current === liveCy) {
298-
liveCy.fit(undefined, 30);
304+
// After layout, fit to last 5 commits for focused view
305+
const recentIds = commits.slice(undefined, 10).map((c) => c.id);
306+
const recentNodes = recentIds.length > 0 ? liveCy.getElementById(recentIds[0]) : liveCy.collection();
307+
for (let i = 1; i < recentIds.length; i++) {
308+
recentNodes.merge(liveCy.getElementById(recentIds[i]));
309+
}
310+
liveCy.fit(recentNodes.nonempty() ? recentNodes : undefined, 30);
299311
}
300312
}
301313
} catch {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"postinstall": "electron-builder install-app-deps",
1919
"electron": "electron .",
2020
"electron-dev": "pnpm build && electron .",
21-
"electron-build": "next build && electron-builder",
21+
"electron-build": "pnpm build && electron-builder",
2222
"build-electron": "npm run build",
2323
"dist": "npm run build-electron && electron-builder",
2424
"audit:security": "pnpm audit --audit-level moderate",

0 commit comments

Comments
 (0)