fix: kept out-of-order todo completions visible

This commit is contained in:
can1357
2026-08-11 15:03:13 +02:00
parent f6d4f1e38b
commit 19edecaa48
2 changed files with 16 additions and 7 deletions
+6 -7
View File
@@ -321,10 +321,10 @@ function selectWithinCap<T extends { status: TodoStatus }>(
*
* Applied to `tasks` in todo order: the open tasks run through
* {@link selectWithinCap}, led by the last {@link COLLAPSED_CLOSED_CONTEXT}
* closed tasks that sit above them so a checked row walks down the list as work
* lands. The lead is additive — it never costs an open row — and a phase with no
* open work left falls back to its closed tasks so the sticky HUD's closed-todo
* persistence still has something to render.
* closed tasks in todo order so a checked row remains visible even when callers
* complete work out of sequence. The lead is additive — it never costs an open
* row — and a phase with no open work left falls back to its closed tasks so the
* sticky HUD's closed-todo persistence still has something to render.
*
* `summary` counts the open tasks that did not fit; the closed lead is context,
* not part of the budget.
@@ -337,9 +337,8 @@ export function selectCollapsedTodos<T extends { status: TodoStatus }>(
const open = tasks.filter(task => !isClosedTodo(task));
// Closed tasks are never active, so a settled phase selects over itself.
if (open.length === 0) return selectWithinCap(tasks, isMatched, cap);
// Everything before the first open task is closed by construction.
const firstOpenIdx = tasks.indexOf(open[0]);
const lead = tasks.slice(Math.max(firstOpenIdx - COLLAPSED_CLOSED_CONTEXT, 0), firstOpenIdx);
// `done` accepts any named task, so closed tasks are not necessarily a prefix.
const lead = tasks.filter(isClosedTodo).slice(-COLLAPSED_CLOSED_CONTEXT);
const selected = selectWithinCap(open, isMatched, cap);
return { items: [...lead, ...selected.items], summary: selected.summary };
}
@@ -732,6 +732,16 @@ describe("selectCollapsedTodos walking viewport (#5873)", () => {
expect(sel.summary).toBe("");
});
it("keeps an out-of-order completion as the closed lead row", () => {
const tasks: TodoItem[] = [
{ content: "current", status: "in_progress" },
{ content: "next", status: "pending" },
{ content: "finished early", status: "completed" },
];
const sel = selectCollapsedTodos(tasks, never, 5);
expect(contents(sel)).toEqual(["finished early", "current", "next"]);
});
it("keeps the closed lead row additive to the open-task cap", () => {
const tasks: TodoItem[] = [{ content: "closed", status: "completed" }, ...mk(5, [1])];
const sel = selectCollapsedTodos(tasks, never, 5);