Disable the fold button when no run is long enough to fold
This commit is contained in:
@@ -38,7 +38,14 @@ describe("buildRows", () => {
|
||||
|
||||
it("does not collapse runs shorter than three", () => {
|
||||
const short = chain("top:p1", "p1:p2", "p2:root", "root");
|
||||
expect(hashes(buildRows(short, new Set(["top"]), true, new Set()))).toHaveLength(4);
|
||||
const r = buildRows(short, new Set(["top"]), true, new Set());
|
||||
expect(hashes(r)).toHaveLength(4);
|
||||
expect(r.collapsible).toBe(false);
|
||||
});
|
||||
|
||||
it("reports when a run can collapse, whether collapsed or not", () => {
|
||||
expect(buildRows(commits, labeled, false, new Set()).collapsible).toBe(true);
|
||||
expect(buildRows(commits, labeled, true, new Set()).collapsible).toBe(true);
|
||||
});
|
||||
|
||||
it("stops a run at merges, forks and labels", () => {
|
||||
|
||||
+5
-1
@@ -4,6 +4,8 @@ export interface RowsResult {
|
||||
rows: DisplayRow[];
|
||||
/** Commit hash → id of the run of plain commits it belongs to. */
|
||||
runOf: Map<string, string>;
|
||||
/** Whether any run is long enough to collapse. */
|
||||
collapsible: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,6 +37,7 @@ export function buildRows(
|
||||
const hidden = new Set<string>();
|
||||
/** First commit of a collapsed run → [last commit, number hidden]. */
|
||||
const jump = new Map<string, [string, number]>();
|
||||
let collapsible = false;
|
||||
|
||||
for (const c of commits) {
|
||||
if (!plain(c.hash) || plain(childOf.get(c.hash))) continue;
|
||||
@@ -47,6 +50,7 @@ export function buildRows(
|
||||
}
|
||||
const id = c.hash;
|
||||
for (const h of run) runOf.set(h, id);
|
||||
if (run.length >= 3) collapsible = true;
|
||||
if (run.length >= 3 && collapseAll !== toggled.has(id)) {
|
||||
for (const h of run.slice(1, -1)) hidden.add(h);
|
||||
jump.set(c.hash, [run[run.length - 1], run.length - 2]);
|
||||
@@ -63,5 +67,5 @@ export function buildRows(
|
||||
: { commit: c, parents: c.parents.map((hash) => ({ hash, dotted: false })) },
|
||||
);
|
||||
}
|
||||
return { rows, runOf };
|
||||
return { rows, runOf, collapsible };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user