Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Notes: no empty checklist item after the last one

Yashwanth Kamireddi9029134ecd0a
diff --git a/.uiverify/notes-follow.mjs b/.uiverify/notes-follow.mjs
index ba42d8b..33fd7de 100644
--- a/.uiverify/notes-follow.mjs
+++ b/.uiverify/notes-follow.mjs
@@ -225,7 +225,9 @@ await page.keyboard.press("Enter");
await page.keyboard.press("Enter");
await page.keyboard.press("ArrowUp");
await page.keyboard.type("Summit plan", { delay: 15 });
-await page.waitForTimeout(1400);
+// Until the save has landed in the library, however busy the machine: a fixed wait failed under load.
+await page.waitForFunction(() => window.__fx.find((n) => n.guid === "nA")?.title === "Summit plan", null, { timeout: 8000 }).catch(() => {});
+await page.waitForTimeout(200);
const aTitle = await row("nA").locator(".note-row-name").innerText();
const aStored = await page.evaluate(() => window.__fx.find((n) => n.guid === "nA").title);
ok(aTitle === "Summit plan" && aTitle === aStored, `a new first line is the title, as the library keeps it (row ${JSON.stringify(aTitle)}, library ${JSON.stringify(aStored)})`);
diff --git a/.uiverify/notes-rich.test.mjs b/.uiverify/notes-rich.test.mjs
index a4c59bc..c92f7f9 100644
--- a/.uiverify/notes-rich.test.mjs
+++ b/.uiverify/notes-rich.test.mjs
@@ -82,3 +82,18 @@ test("only checklist lines move, and only within their own run", () => {
assert.equal(checklistMove(doc, 0, true), null, "alone in its run, it stays");
assert.deepEqual(checklistMove(doc, 2, true), { from: 2, to: 3, before: 4 });
});
+
+test("the empty line after a checklist's closing newline is plain, not one more item", () => {
+ // As a phone stores it: every checklist line, the last one too, ends with its own newline.
+ const text = "Saturday\nFarmers market before 10\nCall Alex about the cabin\n";
+ const runs = [r(9, { style: STYLE.title }), r(25, { style: STYLE.checklist, checked: false }), r(26, { style: STYLE.checklist, checked: false })];
+ const doc = toDoc(text, runs);
+ const last = doc.child(doc.childCount - 1);
+ assert.equal(last.textContent, "");
+ assert.equal(last.attrs.style, null, "no empty checklist item under the last one");
+ assert.equal(doc.child(doc.childCount - 2).attrs.style, STYLE.checklist);
+ const back = fromDoc(doc);
+ assert.equal(back.text, text);
+ // The two checklist lines come back as one run, as Apple's identical runs merge.
+ assert.deepEqual(back.runs, [r(9, { style: STYLE.title }), r(51, { style: STYLE.checklist, checked: false })]);
+});
diff --git a/src/screens/notes/rich.ts b/src/screens/notes/rich.ts
index 7877d5f..7da5334 100644
--- a/src/screens/notes/rich.ts
+++ b/src/screens/notes/rich.ts
@@ -180,7 +180,11 @@ export function toDoc(text: string, runs: Run[] | null): PMNode {
const nl = text.indexOf("\n", start);
const end = nl < 0 ? text.length : nl;
// A paragraph is set by the run its newline is in — or, for the last line, its last unit.
- const own = fits ? (units[nl < 0 ? Math.max(end - 1, start) : nl] ?? units[units.length - 1]) : null;
+ // The empty line after a note's closing newline has no run of its own: it is plain text, as
+ // Notes shows it. Taking the newline's run before it drew an empty checklist item (or bullet)
+ // under the last one, which the phone never shows.
+ const trailing = nl < 0 && start === text.length && start > 0;
+ const own = fits && !trailing ? (units[nl < 0 ? Math.max(end - 1, start) : nl] ?? units[units.length - 1]) : null;
const inline: PMNode[] = [];
let i = start;
while (i < end) {