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 show their formatting as Notes sets it — title, heading, subheading, monospaced, bulleted, dashed and numbered lists, checklists with their ticks, bold, italic, underline, strikethrough, links — from Apple's runs; a click into the text edits it

Yashwanth Kamireddie1b1f3b67e62
diff --git a/.uiverify/notes-formatted.mjs b/.uiverify/notes-formatted.mjs
new file mode 100644
index 0000000..f43e68e
--- /dev/null
+++ b/.uiverify/notes-formatted.mjs
@@ -0,0 +1,24 @@
+// A note formatted on a phone shows formatted here: its checklist with ticks, its dashed
+// list; a click into it is editing.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1200, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, notesFixture: true });
+const page = await ctx.newPage();
+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+await openScreen(page, "Notes");
+await page.locator(".note-row", { hasText: "Curtains" }).click();
+await page.waitForTimeout(400);
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+const ticked = await page.locator(".nf-check.is-done").count();
+const marks = await page.locator(".nf-mark").allInnerTexts();
+ok(ticked === 1, `a ticked checklist item shows ticked [${ticked}]`);
+ok(marks.length > 0 && marks.every((m) => m === "–"), `a dashed list shows its dashes ${JSON.stringify(marks.slice(0, 3))}`);
+await page.locator(".note-read").click();
+await page.waitForTimeout(200);
+ok(await page.evaluate(() => document.activeElement?.classList.contains("note-text") && document.activeElement.tagName === "TEXTAREA"),
+ "a click into it is editing");
+await b.close();
+process.exitCode = failures ? 1 : 0;
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index 572efe9..e277404 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -168,6 +168,16 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
case "reminder_list_create": case "reminder_list_rename": case "reminder_list_delete":
return null;
case "reminders_smart": return !remindersFixture || remindersFixture === "lists" ? [] : reminderItems.filter(r => !r.completedAt);
+ case "note_runs": {
+ // Curtains, set as a phone sets one: a title, then a dashed list and a ticked item.
+ if (args.guid !== "n1") return [];
+ const body = (noteList.find((n) => n.guid === "n1") ?? {}).body ?? "";
+ const lines = body.split("\n");
+ const runs = lines.map((l, i) => ({ length: l.length + (i < lines.length - 1 ? 1 : 0),
+ style: i === 0 ? 0 : i === 1 ? 103 : 101, indent: 0, checked: i === 1 ? true : null,
+ bold: false, italic: false, underline: false, strike: false, link: null }));
+ return runs;
+ }
case "note_folders": return !notesFixture ? [] : (window.__noteFolders ??= noteFolders.slice()).slice();
case "note_folder_create": {
const guid = `f-${(window.__noteFolders ??= noteFolders.slice()).length + 1}`;
diff --git a/check.sh b/check.sh
index 67ec7fd..e786b5f 100755
--- a/check.sh
+++ b/check.sh
@@ -62,6 +62,7 @@ step "reminder date" node .uiverify/reminders-date.mjs
step "contacts order" node .uiverify/contacts-order.mjs
step "calendar alerts" node .uiverify/calendar-alerts.mjs
step "reminder add/done" node .uiverify/reminders-add-done.mjs
+step "notes formatted" node .uiverify/notes-formatted.mjs
# The same screens in WebKit, the engine Quince draws in. Chromium above catches most things;
# this catches what only WebKit does — pointer capture, blur on removal, its own layout.
diff --git a/src/lib/ipc.ts b/src/lib/ipc.ts
index c3d2397..40542d0 100644
--- a/src/lib/ipc.ts
+++ b/src/lib/ipc.ts
@@ -120,6 +120,7 @@ export const api = {
invoke<void>("reminder_delete", { guid, listGuid }),
noteFolders: () => invoke<NoteFolder[]>("note_folders"),
+ noteRuns: (guid: string) => invoke<import("../screens/notes/Formatted").Run[]>("note_runs", { guid }),
noteFolderCreate: (title: string, parent: string | null) =>
invoke<string>("note_folder_create", { title, parent }),
noteFolderRename: (guid: string, title: string) => invoke<void>("note_folder_rename", { guid, title }),
diff --git a/src/screens/NotesView.tsx b/src/screens/NotesView.tsx
index dd598c1..5f01372 100644
--- a/src/screens/NotesView.tsx
+++ b/src/screens/NotesView.tsx
@@ -6,6 +6,7 @@ import { LongTextarea } from "../components/LongTextarea";
import { editorDate, groupNotes, joinTitle, listDate, splitTitle } from "./notes/model";
import { api, messageOf, nestFolders, type Note, type NoteFolder } from "../lib/ipc";
import { RowMenu } from "../components/RowMenu";
+import { FormattedBody, runsFit, type Run } from "./notes/Formatted";
import { useSync } from "../lib/sync";
import { Picker } from "../components/Picker";
@@ -177,8 +178,26 @@ export function NotesView() {
};
}, [openGuid, revision]);
+ /** How the open note is set, from Apple's attribute runs, read with its body. */
+ const [loadedRuns, setLoadedRuns] = useState<{ guid: string; runs: Run[] } | null>(null);
+ /** Showing the note formatted; a click into its text switches to editing it. */
+ const [reading, setReading] = useState(true);
+ useEffect(() => {
+ setReading(true);
+ if (!openGuid) return setLoadedRuns(null);
+ let cancelled = false;
+ api.noteRuns(openGuid).then(
+ (runs) => { if (!cancelled) setLoadedRuns({ guid: openGuid, runs: Array.isArray(runs) ? runs : [] }); },
+ () => {},
+ );
+ return () => { cancelled = true; };
+ }, [openGuid, revision]);
+
/** What the open note says, or null while that is still unknown. */
const body = open && loadedBody?.guid === open.guid ? loadedBody.text : null;
+ const runs = open && loadedRuns?.guid === open.guid ? loadedRuns.runs : null;
+ // Formatted only while it is exactly what Apple holds: untouched here, the runs adding up.
+ const formatted = Boolean(body !== null && runs && draft === null && runsFit(body, runs));
const dirty = draft !== null && body !== null && draft !== body;
@@ -785,6 +804,28 @@ export function NotesView() {
void (composingRef.current ? commitComposing() : flush());
}}
/>
+ {reading && formatted && !composing ? (
+ <div
+ className="note-text note-read"
+ role="textbox"
+ aria-readonly="false"
+ aria-label={`Body of ${open?.title ?? "note"}`}
+ tabIndex={0}
+ onClick={() => {
+ setReading(false);
+ window.setTimeout(() => bodyEditor.current?.focus(), 0);
+ }}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ setReading(false);
+ window.setTimeout(() => bodyEditor.current?.focus(), 0);
+ }
+ }}
+ >
+ <FormattedBody text={body ?? ""} runs={runs ?? []} skip={titleLine.length + 1} />
+ </div>
+ ) : (
<LongTextarea
key="body"
ref={bodyEditor}
@@ -811,6 +852,7 @@ export function NotesView() {
void (composingRef.current ? commitComposing() : flush());
}}
/>
+ )}
</div>
) : open?.locked ? (
<p className="cal-empty">
@@ -826,7 +868,13 @@ export function NotesView() {
) : open ? (
<div className="note-editor is-readonly">
<h1 className="note-title">{splitTitle(body ?? "").title}</h1>
- <pre className="note-text">{splitTitle(body ?? "").rest}</pre>
+ {runs && body !== null && runsFit(body, runs) ? (
+ <div className="note-text note-read">
+ <FormattedBody text={body} runs={runs} skip={splitTitle(body).title.length + 1} />
+ </div>
+ ) : (
+ <pre className="note-text">{splitTitle(body ?? "").rest}</pre>
+ )}
<p className="note-readonly">
Quince can’t yet save changes to this note without risking what is in it — it
is very long, or its copy on iCloud is out of step with your devices — so it is
diff --git a/src/screens/notes/Formatted.tsx b/src/screens/notes/Formatted.tsx
new file mode 100644
index 0000000..3b62f17
--- /dev/null
+++ b/src/screens/notes/Formatted.tsx
@@ -0,0 +1,151 @@
+/**
+ * A note as Notes sets it: titles and headings, bulleted, dashed and numbered lists, checklists
+ * with their circles, monospaced blocks, and bold, italic, underlined, struck and linked text —
+ * read from Apple's own attribute runs, so what a phone or icloud.com formatted shows here
+ * the same.
+ *
+ * A run's length counts UTF-16 units, which is how a JavaScript string counts, so the runs
+ * lay over the text directly. Runs that do not add up to the text — a note edited here since
+ * the last sync — are not guessed at: the caller shows the plain text instead.
+ */
+export type Run = {
+ length: number;
+ style: number | null;
+ indent: number;
+ checked: boolean | null;
+ bold: boolean;
+ italic: boolean;
+ underline: boolean;
+ strike: boolean;
+ link: string | null;
+};
+
+/** Apple's paragraph styles. */
+export const STYLE = {
+ title: 0,
+ heading: 1,
+ subheading: 2,
+ body: 3,
+ mono: 4,
+ bulleted: 100,
+ dashed: 101,
+ numbered: 102,
+ checklist: 103,
+} as const;
+
+/** Whether `runs` describe exactly this text. */
+export function runsFit(text: string, runs: Run[]): boolean {
+ return runs.length > 0 && runs.reduce((n, r) => n + r.length, 0) === text.length;
+}
+
+type Span = { text: string; run: Run };
+type Paragraph = { spans: Span[]; run: Run; start: number };
+
+/** The text cut into paragraphs, each with the style of the run its line ends in. */
+function paragraphs(text: string, runs: Run[]): Paragraph[] {
+ const out: Paragraph[] = [];
+ let current: Paragraph = { spans: [], run: runs[0], start: 0 };
+ let at = 0;
+ for (const run of runs) {
+ let piece = text.slice(at, at + run.length);
+ let offset = at;
+ at += run.length;
+ while (piece.length > 0) {
+ const nl = piece.indexOf("\n");
+ const part = nl < 0 ? piece : piece.slice(0, nl);
+ if (part) current.spans.push({ text: part, run });
+ if (nl < 0) {
+ current.run = run;
+ break;
+ }
+ // The newline carries the paragraph's style, as Apple stores it.
+ current.run = run;
+ out.push(current);
+ offset += nl + 1;
+ current = { spans: [], run, start: offset };
+ piece = piece.slice(nl + 1);
+ }
+ }
+ if (current.spans.length > 0 || out.length === 0) out.push(current);
+ return out;
+}
+
+function Inline({ span }: { span: Span }) {
+ const { run, text } = span;
+ let node: React.ReactNode = text;
+ if (run.bold) node = <strong>{node}</strong>;
+ if (run.italic) node = <em>{node}</em>;
+ if (run.underline) node = <u>{node}</u>;
+ if (run.strike) node = <s>{node}</s>;
+ if (run.link) {
+ node = (
+ <a href={run.link} target="_blank" rel="noreferrer" onClick={(e) => e.stopPropagation()}>
+ {node}
+ </a>
+ );
+ }
+ return <>{node}</>;
+}
+
+/**
+ * The body below the title. `skip` is how much of the text the title line takes, so the
+ * runs still line up with what is drawn.
+ */
+export function FormattedBody({
+ text,
+ runs,
+ skip,
+ onTick,
+}: {
+ text: string;
+ runs: Run[];
+ skip: number;
+ onTick?: (paragraphStart: number, checked: boolean) => void;
+}) {
+ const all = paragraphs(text, runs).filter((p) => p.start >= skip);
+ let number = 0;
+ return (
+ <div className="note-formatted">
+ {all.map((p, i) => {
+ const style = p.run?.style ?? STYLE.body;
+ number = style === STYLE.numbered ? number + 1 : 0;
+ const indent = { paddingInlineStart: `${(p.run?.indent ?? 0) * 1.5}em` };
+ const content = p.spans.length ? p.spans.map((s, j) => <Inline key={j} span={s} />) : <br />;
+ if (style === STYLE.title) return <h2 key={i} className="nf-title" style={indent}>{content}</h2>;
+ if (style === STYLE.heading) return <h3 key={i} className="nf-heading" style={indent}>{content}</h3>;
+ if (style === STYLE.subheading) return <h4 key={i} className="nf-subheading" style={indent}>{content}</h4>;
+ if (style === STYLE.mono) return <pre key={i} className="nf-mono" style={indent}>{content}</pre>;
+ if (style === STYLE.checklist) {
+ const done = Boolean(p.run?.checked);
+ return (
+ <p key={i} className={`nf-item nf-check${done ? " is-done" : ""}`} style={indent}>
+ <button
+ type="button"
+ className="nf-circle"
+ role="checkbox"
+ aria-checked={done}
+ aria-label={p.spans.map((s) => s.text).join("") || "Checklist item"}
+ disabled={!onTick}
+ onClick={(e) => {
+ e.stopPropagation();
+ onTick?.(p.start, !done);
+ }}
+ />
+ <span>{content}</span>
+ </p>
+ );
+ }
+ if (style === STYLE.bulleted || style === STYLE.dashed || style === STYLE.numbered) {
+ const mark = style === STYLE.bulleted ? "•" : style === STYLE.dashed ? "–" : `${number}.`;
+ return (
+ <p key={i} className="nf-item" style={indent}>
+ <span className="nf-mark" aria-hidden="true">{mark}</span>
+ <span>{content}</span>
+ </p>
+ );
+ }
+ return <p key={i} className="nf-body" style={indent}>{content}</p>;
+ })}
+ </div>
+ );
+}
diff --git a/src/styles/notes.css b/src/styles/notes.css
index c896a68..09ce069 100644
--- a/src/styles/notes.css
+++ b/src/styles/notes.css
@@ -265,3 +265,26 @@ textarea.note-title::placeholder { color: var(--text-3); }
background: none; box-shadow: none; color: var(--gold); font: inherit; font-size: var(--t-13); cursor: pointer;
}
.notes-new-folder:hover { text-decoration: underline; }
+/* A note as Notes sets it, from Apple's own runs. Sizes after Notes on macOS: title 24,
+ heading 19, subheading 16, body 15. */
+.note-read { cursor: text; outline: none; }
+.note-formatted { font-size: var(--t-15); line-height: 1.55; overflow-wrap: anywhere; }
+.note-formatted p, .note-formatted h2, .note-formatted h3, .note-formatted h4, .note-formatted pre { margin: 0; }
+.nf-title { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; margin-top: 6px !important; }
+.nf-heading { font-size: 19px; font-weight: 700; line-height: 1.35; margin-top: 4px !important; }
+.nf-subheading { font-size: 16px; font-weight: 600; }
+.nf-mono { font-family: ui-monospace, "SF Mono", "JetBrains Mono", monospace; font-size: 13.5px; white-space: pre-wrap; }
+.nf-body { white-space: pre-wrap; min-height: 1.55em; }
+.nf-item { display: grid; grid-template-columns: 1.6em minmax(0, 1fr); align-items: baseline; white-space: pre-wrap; }
+.nf-mark { color: var(--text-2); text-align: left; font-variant-numeric: tabular-nums; }
+.nf-check { align-items: center; }
+.nf-circle {
+ width: 17px; height: 17px; padding: 0; border: 1.5px solid var(--text-3); border-radius: 50%;
+ background: none; box-shadow: none; cursor: pointer; transition: background 120ms ease, border-color 120ms ease;
+}
+.nf-check.is-done .nf-circle {
+ border-color: var(--gold); background: var(--gold)
+ url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M4 8.2l2.6 2.6L12 5.4' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>") center/12px no-repeat;
+}
+.nf-check.is-done > span:last-child { color: var(--text-3); }
+.note-formatted a { color: var(--gold); text-decoration: underline; }