Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Notes: a nested numbered list counts on its own, as the phone does
Yashwanth Kamireddifda0912d5ce4
diff --git a/.uiverify/notes-numbered.mjs b/.uiverify/notes-numbered.mjsnew file mode 100644index 0000000..22cdead--- /dev/null+++ b/.uiverify/notes-numbered.mjs@@ -0,0 +1,58 @@+// A numbered list with one nested in it, as a phone numbers it: the nested items count from 1+// on their own, and the outer list carries on after them — 1, (1, 2), 2 — in the editor and in a+// note shown read-only. One count for every depth had the outer list go on from 4.+import { engine } from "./engine.mjs";+import { SERVICES, installStub, openScreen } from "./stub.mjs";+const BASE = process.env.BASE ?? "http://localhost:4202";+const b = await engine.launch();+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };++const lines = [["Steps", 0, null], ["Pack", 0, 102], ["Socks", 1, 102], ["Boots", 1, 102], ["Drive", 0, 102], ["Done", 0, null]];+const body = lines.map(([t]) => t).join("\n");+const runs = lines.map(([t, indent, style], i) => ({ length: t.length + (i < lines.length - 1 ? 1 : 0), style: i === 0 ? 0 : style, indent,+ checked: null, bold: false, italic: false, underline: false, strike: false, link: null }));+const note = (guid, editable) => ({ guid, folderGuid: "f1", title: "Steps", snippet: "", body, locked: false, editable, pinned: false,+ createdAt: null, modifiedAt: 1789900000 + (editable ? 1 : 0), etag: null });++const ctx = await b.newContext({ viewport: { width: 1200, height: 800 } });+await ctx.addInitScript(([notes, runs]) => {+ window.__notesExtra = notes;+ window.__savedRuns = Object.fromEntries(notes.map((n) => [n.guid, runs]));+}, [[note("nNum", true), note("nNumRO", false)], runs]);+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, notesFixture: true });+const page = await ctx.newPage();+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); failures++; });+await page.goto(BASE, { waitUntil: "networkidle" });+await openScreen(page, "Notes");++await page.locator('.note-row[data-guid="nNum"]').click();+await page.waitForTimeout(500);+const shown = await page.locator('.note-rich .nf-p[data-style="102"]').evaluateAll((ps) => ps.map((p) => `${p.getAttribute("data-n")}. ${p.textContent}`));+ok(JSON.stringify(shown) === JSON.stringify(["1. Pack", "1. Socks", "2. Boots", "2. Drive"]), `editor: ${JSON.stringify(shown)}`);+const drawn = await page.locator('.note-rich .nf-p[data-style="102"]').first().evaluate((p) => getComputedStyle(p, "::before").content);+ok(/attr\(data-n\)|"1\."/.test(drawn) || drawn.includes("1"), `and the number is what is drawn ${drawn}`);++// A new item typed under the nested one counts on from it.+await page.waitForTimeout(600);+const boots = page.locator('.note-rich .nf-p', { hasText: "Boots" });+const bb = await boots.boundingBox();+// At the end of its words, past the number's gutter.+await page.mouse.click(bb.x + bb.width - 4, bb.y + bb.height / 2);+await page.waitForTimeout(150);+await page.keyboard.press("End");+await page.keyboard.press("Enter");+await page.keyboard.type("Hat");+await page.waitForTimeout(200);+const typed = await page.locator('.note-rich .nf-p[data-style="102"]').evaluateAll((ps) => ps.map((p) => `${p.getAttribute("data-n")}. ${p.textContent}`));+ok(JSON.stringify(typed) === JSON.stringify(["1. Pack", "1. Socks", "2. Boots", "3. Hat", "2. Drive"]), `a new nested item: ${JSON.stringify(typed)}`);++await page.waitForTimeout(1200);+await page.locator('.note-row[data-guid="nNumRO"]').click();+await page.waitForTimeout(500);+await page.locator(".note-formatted").waitFor({ timeout: 3000 }).catch(async () => console.log(await page.locator(".note-detail, .note-editor").first().evaluate((e) => e.outerHTML.slice(0, 400)).catch(() => "none")));+const read = await page.locator(".note-formatted .nf-item").evaluateAll((ps) => ps.map((p) => p.innerText.replace(/\s+/g, " ").trim()));+ok(JSON.stringify(read) === JSON.stringify(["1. Pack", "1. Socks", "2. Boots", "2. Drive"]), `read-only: ${JSON.stringify(read)}`);++await b.close();+process.exitCode = failures ? 1 : 0;diff --git a/.uiverify/notes-rich.test.mjs b/.uiverify/notes-rich.test.mjsindex c92f7f9..835c94e 100644--- a/.uiverify/notes-rich.test.mjs+++ b/.uiverify/notes-rich.test.mjs@@ -97,3 +97,17 @@ test("the empty line after a checklist's closing newline is plain, not one more// 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 })]);});++import { listNumbers } from "../src/screens/notes/rich.ts";+test("a numbered list nested in another counts on its own, and the outer one carries on", () => {+ const n = (indent, start = null) => ({ style: STYLE.numbered, indent, start });+ const lines = [+ { style: STYLE.title, indent: 0 },+ n(0), n(1), n(1), n(2), n(1), n(0),+ { style: null, indent: 0 },+ n(0, 5), n(0), n(1),+ ];+ // As a phone numbers it, and as Markdown export (markdown.rs) does: 1, 1, 2, 1, 3, 2; a plain+ // line ends the list; one begun at 5 goes on 6, its nested item from 1.+ assert.deepEqual(listNumbers(lines), [null, 1, 1, 2, 1, 3, 2, null, 5, 6, 1]);+});diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjsindex a7c0ca9..ea2e1d3 100644--- a/.uiverify/stub.mjs+++ b/.uiverify/stub.mjs@@ -533,6 +533,8 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note}case "note_create": return "Note/new";case "notes_in":+ // A suite's own notes (`window.__notesExtra`), their formatting in `__savedRuns`.+ for (const n of window.__notesExtra ?? []) if (!noteList.some((x) => x.guid === n.guid)) noteList.unshift({ ...n });// Opt-in: a note holding a table, as a phone makes one.if (window.__mediaNote && !noteList.some((n) => n.guid === "nM"))noteList.unshift({ guid: "nM", folderGuid: "f1", title: "Trip", snippet: "", body: "Trip\n\uFFFC\n\uFFFC\nend",diff --git a/src/screens/notes/Formatted.tsx b/src/screens/notes/Formatted.tsxindex 6b8aa9a..37c340b 100644--- a/src/screens/notes/Formatted.tsx+++ b/src/screens/notes/Formatted.tsx@@ -11,6 +11,7 @@import { useEffect, useRef } from "react";import { describe, drawMedia } from "./NoteEditor";import { addressesIn, openLinkAt } from "./links";+import { listNumbers } from "./rich";import { REFUSED_LINK, linkedNote, outsideHref } from "../../lib/links";export type Run = {length: number;@@ -185,12 +186,12 @@ export function FormattedBody({onTick?: (paragraphStart: number, checked: boolean) => void;}) {const all = paragraphs(text, runs).filter((p) => p.start >= skip);- let number = 0;+ // Counted as the editor counts them: a nested list on its own, the outer one carrying on.+ const numbers = listNumbers(all.map((p) => ({ style: p.run?.style ?? STYLE.body, indent: p.run?.indent ?? 0, start: p.run?.start ?? null })));return (<div className="note-formatted">{all.map((p, i) => {const style = p.run?.style ?? STYLE.body;- number = style === STYLE.numbered ? (p.run?.start ?? number + 1) : 0;const indent = { paddingInlineStart: `${(p.run?.indent ?? 0) * 1.5}em` };const at = { "data-start": p.start, ...(p.run?.quote ? { "data-quote": "true" } : {}) } as Record<string, number | string>;const content = p.spans.length ? p.spans.map((s, j) => <Inline key={j} span={s} />) : <br />;@@ -219,7 +220,7 @@ export function FormattedBody({);}if (style === STYLE.bulleted || style === STYLE.dashed || style === STYLE.numbered) {- const mark = style === STYLE.bulleted ? "•" : style === STYLE.dashed ? "–" : `${number}.`;+ const mark = style === STYLE.bulleted ? "•" : style === STYLE.dashed ? "–" : `${numbers[i]}.`;return (<p key={i} className="nf-item" style={indent} {...at}><span className="nf-mark" aria-hidden="true">{mark}</span>diff --git a/src/screens/notes/NoteEditor.tsx b/src/screens/notes/NoteEditor.tsxindex 4517ef5..5ac1c58 100644--- a/src/screens/notes/NoteEditor.tsx+++ b/src/screens/notes/NoteEditor.tsx@@ -1,13 +1,13 @@import "prosemirror-view/style/prosemirror.css";import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";import { EditorState, Plugin, TextSelection, type Command, type Transaction } from "prosemirror-state";-import { EditorView } from "prosemirror-view";+import { Decoration, DecorationSet, EditorView } from "prosemirror-view";import { history, undo, redo } from "prosemirror-history";import { keymap } from "prosemirror-keymap";import { baseKeymap, splitBlockAs, toggleMark, chainCommands } from "prosemirror-commands";import { Fragment, Slice, type Node as PMNode } from "prosemirror-model";import type { Run } from "./Formatted";-import { checklistMove, fromDoc, LIST_STYLES, schema, STYLE, tableCells, toDoc } from "./rich";+import { checklistMove, fromDoc, listNumbers, LIST_STYLES, schema, STYLE, tableCells, toDoc } from "./rich";import { MOVE_CHECKED_KEY } from "./model";function moveCheckedOn(): boolean {@@ -580,6 +580,30 @@ function moveLines(by: 1 | -1): Command {};}+/** Each numbered line's number (`data-n`, which the stylesheet draws), counted as Notes counts+ * them (rich.ts listNumbers) — worked out again only when the note changes. */+function numbering(doc: PMNode): DecorationSet {+ const lines: PMNode[] = [];+ const at: number[] = [];+ doc.forEach((node, offset) => {+ lines.push(node);+ at.push(offset);+ });+ const numbers = listNumbers(lines.map((n) => n.attrs as { style: number | null; indent: number; start: number | null }));+ const marks: Decoration[] = [];+ numbers.forEach((n, i) => {+ if (n !== null) marks.push(Decoration.node(at[i], at[i] + lines[i].nodeSize, { "data-n": String(n) }));+ });+ return DecorationSet.create(doc, marks);+}+const numbered: Plugin<DecorationSet> = new Plugin<DecorationSet>({+ state: {+ init: (_, state) => numbering(state.doc),+ apply: (tr, was) => (tr.docChanged ? numbering(tr.doc) : was),+ },+ props: { decorations: (state): DecorationSet | undefined => numbered.getState(state) },+});+const parentOf = (state: EditorState) => state.selection.$from.parent;const inList = (state: EditorState) => LIST_STYLES.includes(parentOf(state).attrs.style);@@ -728,6 +752,7 @@ export const NoteEditor = forwardRef<EditorHandle, Props>(function NoteEditor(plugins: [letTabOut,autolink,+ numbered,history(),keymap({"Mod-z": undo,diff --git a/src/screens/notes/rich.ts b/src/screens/notes/rich.tsindex 7da5334..bae6017 100644--- a/src/screens/notes/rich.ts+++ b/src/screens/notes/rich.ts@@ -350,6 +350,28 @@ export function sameFormatting(text: string, a: Run[] | null, b: Run[] | null):return x !== null && y !== null && JSON.stringify(x) === JSON.stringify(y);}+/**+ * The number each line of a numbered list shows, as Notes numbers them (and as Markdown export+ * does, markdown.rs): a list nested in another counts from 1 on its own, and the list around it+ * carries on after it; a line that is not numbered ends every list; a list's first item may+ * start it elsewhere. Null for a line that is not numbered. One count for every depth had a+ * nested list's items counted into the outer list, so it went on from 4 where the phone shows 2.+ */+export function listNumbers(lines: { style: number | null; indent: number; start?: number | null }[]): (number | null)[] {+ const counts: number[] = [];+ return lines.map((line) => {+ if (line.style !== STYLE.numbered) {+ counts.length = 0;+ return null;+ }+ const depth = Math.max(0, line.indent | 0);+ counts.length = Math.min(counts.length, depth + 1);+ while (counts.length <= depth) counts.push(0);+ counts[depth] = counts[depth] === 0 && line.start ? line.start : counts[depth] + 1;+ return counts[depth];+ });+}+/*** Where a checklist item goes when it is ticked or unticked with "Sort Checked Items* Automatically" on, as Notes sorts them: ticked, the item — with the items nested under it — goesdiff --git a/src/styles/notes.css b/src/styles/notes.cssindex a777fda..34d657c 100644--- a/src/styles/notes.css+++ b/src/styles/notes.css@@ -270,9 +270,8 @@ textarea.note-title::placeholder { color: var(--text-3); }}.note-rich .nf-p[data-style="100"]::before { content: "•"; }.note-rich .nf-p[data-style="101"]::before { content: "–"; }-.note-rich .nf-p:not([data-style="102"]) { counter-reset: nf-num; }-.note-rich .nf-p[data-style="102"] { counter-increment: nf-num; }-.note-rich .nf-p[data-style="102"]::before { content: counter(nf-num) "."; }+/* Its number, counted by the editor as Notes counts them (a nested list on its own). */+.note-rich .nf-p[data-style="102"]::before { content: attr(data-n) "."; }/* A checklist item's circle: clicking it ticks the line (the editor reads the click). *//* A checklist circle, crisp as Notes draws it: an 18px vector ring masked over the theme's colourand set on whole pixels. The CSS border it replaced was 17px with a 1.5px edge at a fractional