From 3c747157898fe9b15ed37b6fbeb1d93f3291eeb3 Mon Sep 17 00:00:00 2001 From: ctrl-q <34975747+ctrl-q@users.noreply.github.com> Date: Sat, 1 Aug 2026 11:57:53 -0400 Subject: [PATCH] fix: exclude cancelled TODOs from checklist progress bar Cancelled inline checklist items (- [-]) were being counted toward the progress bar's denominator but never the numerator, making tasks with cancelled items appear less complete than they actually are (e.g. 1 done + 1 cancelled showed as 1/2 instead of 1/1). Cancelled items are now excluded entirely from both the numerator and denominator of the checklist progress calculation. Fixes #2182 --- src/ui/taskCardProperties.ts | 5 ++- .../issue-1576-display-progress-bar.test.ts | 45 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/ui/taskCardProperties.ts b/src/ui/taskCardProperties.ts index 9a1c5bedc..cc2ee9f7a 100644 --- a/src/ui/taskCardProperties.ts +++ b/src/ui/taskCardProperties.ts @@ -222,8 +222,11 @@ function calculateChecklistProgress(cache: unknown): ChecklistProgress | null { const isNested = typeof item.parent === "number" && item.parent >= 0; if (isNested) continue; + const marker = item.task.toLowerCase(); + if (marker === "-") continue; // cancelled — excluded from progress count + total += 1; - if (item.task.toLowerCase() === "x") { + if (marker === "x") { completed += 1; } } diff --git a/tests/unit/issues/issue-1576-display-progress-bar.test.ts b/tests/unit/issues/issue-1576-display-progress-bar.test.ts index abc3124fd..0d189b00b 100644 --- a/tests/unit/issues/issue-1576-display-progress-bar.test.ts +++ b/tests/unit/issues/issue-1576-display-progress-bar.test.ts @@ -199,7 +199,7 @@ describe("Issue #1576 - Display Progress Bar on task cards", () => { expect((card.querySelector(".task-card__progress-fill") as HTMLElement).style.width).toBe("100%"); }); - it("treats non-x task markers as incomplete", () => { + it("treats non-x, non-dash task markers as incomplete", () => { const task = TaskFactory.createTask({ path: "tasks/custom-marker-task.md", title: "Custom marker", @@ -209,7 +209,7 @@ describe("Issue #1576 - Display Progress Bar on task cards", () => { app.metadataCache.setCache(task.path, { frontmatter: { title: task.title }, listItems: [ - listItem("-", -1, 10), // not completed + listItem("/", -1, 10), // not completed listItem("x", -1, 11), // completed ], }); @@ -218,4 +218,45 @@ describe("Issue #1576 - Display Progress Bar on task cards", () => { expect(card.querySelector(".task-card__progress-label")?.textContent).toBe("1/2"); expect((card.querySelector(".task-card__progress-fill") as HTMLElement).style.width).toBe("50%"); }); + + it("excludes cancelled (- [-]) items from both numerator and denominator", () => { + const task = TaskFactory.createTask({ + path: "tasks/cancelled-marker-task.md", + title: "Cancelled marker", + }); + + MockObsidian.createTestFile(task.path, "# Cancelled marker"); + app.metadataCache.setCache(task.path, { + frontmatter: { title: task.title }, + listItems: [ + listItem("-", -1, 10), // cancelled — excluded entirely + listItem("x", -1, 11), // completed + ], + }); + + const card = createTaskCard(task, plugin, ["checklistProgress"]); + expect(card.querySelector(".task-card__progress-label")?.textContent).toBe("1/1"); + expect((card.querySelector(".task-card__progress-fill") as HTMLElement).style.width).toBe("100%"); + }); + + it("does not render checklist progress when only cancelled checkboxes exist", () => { + const task = TaskFactory.createTask({ + path: "tasks/all-cancelled-task.md", + title: "All cancelled", + }); + + MockObsidian.createTestFile(task.path, "# All cancelled"); + app.metadataCache.setCache(task.path, { + frontmatter: { title: task.title }, + listItems: [ + listItem("-", -1, 10), + listItem("-", -1, 11), + ], + }); + + const card = createTaskCard(task, plugin, ["checklistProgress"]); + expect(card.querySelector(".task-card__progress")).toBeNull(); + const metadata = card.querySelector(".task-card__metadata") as HTMLElement; + expect(metadata.style.display).toBe("none"); + }); });