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
Reminders: Return on a reminder begins the next one right below it
Yashwanth Kamireddif6058d65a716
diff --git a/.uiverify/reminders-keys.mjs b/.uiverify/reminders-keys.mjsindex 77c686d..ce2d9d6 100644--- a/.uiverify/reminders-keys.mjs+++ b/.uiverify/reminders-keys.mjs@@ -1,5 +1,5 @@// Reminders' keys, as on a Mac: Tab tucks a reminder under the one above, at once;-// Shift-Tab brings it back out; Return goes on to a new reminder.+// Shift-Tab brings it back out; Return goes on to a new reminder below it.import { engine } from "./engine.mjs";import { SERVICES, installStub, openScreen } from "./stub.mjs";const b = await engine.launch();@@ -49,7 +49,12 @@ ok(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")await page.getByLabel("Rename Pick up the parcel").focus();await page.keyboard.press("Enter");await page.waitForTimeout(150);-ok(await page.evaluate(() => document.activeElement?.closest(".rx-add") !== null), "Return goes on to a new reminder");+// Right below it, as on the Mac (reminders-next-below.mjs has the rest); Escape ends it there.+ok(await page.evaluate(() => {+ const next = document.activeElement?.closest(".rx-next");+ return next?.previousElementSibling?.querySelector(".rx-title")?.value === "Pick up the parcel";+}), "Return goes on to a new reminder, right below it");+await page.keyboard.press("Escape");// Drag to reorder: the row lands where it is dropped, at once, and Apple is asked.const titles = () => page.locator(".rx-row:not(.is-done) .rx-title").evaluateAll((els) => els.map((e) => e.value));const before = await titles();diff --git a/.uiverify/reminders-next-below.mjs b/.uiverify/reminders-next-below.mjsnew file mode 100644index 0000000..5800e21--- /dev/null+++ b/.uiverify/reminders-next-below.mjs@@ -0,0 +1,93 @@+// Return on a reminder in a list begins the next one right below it, as on the Mac: the new+// row is there at once in that place, goes to Apple in that place (put before the reminder+// that followed), and the field goes on below it for another. Return on an empty one ends it;+// a subtask's next is a subtask of the same reminder; leaving the field with words adds them.+// BASE=http://localhost:4173 ENGINE=webkit node .uiverify/reminders-next-below.mjs+import { engine } from "./engine.mjs";+import { SERVICES, installStub, openScreen } from "./stub.mjs";++const BASE = process.env.BASE ?? "http://localhost:4173";+const b = await engine.launch();+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };+const until = (page, fn, arg) => page.waitForFunction(fn, arg, { timeout: 8000, polling: "raf" }).then(() => true, () => false);++const ctx = await b.newContext({ viewport: { width: 1200, height: 800 } });+await ctx.addInitScript(() => {+ const r = (guid, title, parentGuid = null) => ({ guid, listGuid: "l3", title, notes: null, dueAt: null, allDay: false,+ completedAt: null, priority: 0, flagged: false, parentGuid, etag: null });+ window.__extraReminders = [r("a", "Learn to swim"), r("a1", "Find a pool", "a"), r("b", "Run a marathon"), r("c", "See the northern lights")];+ window.__filterLists = true;+});+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, remindersFixture: true });+const page = await ctx.newPage();+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));+await page.goto(BASE, { waitUntil: "networkidle" });+await openScreen(page, "Reminders");+await page.locator(".rx-list", { hasText: "Life Goals" }).click();+await until(page, () => document.querySelectorAll(".rx-row .rx-title").length >= 4);++const titles = () => page.locator(".rx-rows > li").evaluateAll((els) =>+ els.map((e) => (e.classList.contains("rx-next") ? "[next]" : e.querySelector(".rx-title")?.value)));++// Return on "Learn to swim": the field is below it and its subtask, not at the foot.+await page.getByLabel("Rename Learn to swim").focus();+await page.keyboard.press("Enter");+ok(await until(page, () => document.activeElement?.closest(".rx-next") !== null), "Return opens a new reminder, its field focused");+let shown = await titles();+ok(shown.join("|") === "Learn to swim|Find a pool|[next]|Run a marathon|See the northern lights", `right below it and its subtask (${shown.join(" | ")})`);++// Typed and Return: there at once, in that place, the field going on below it.+await page.keyboard.type("Learn to dive");+await page.keyboard.press("Enter");+ok(await until(page, () => [...document.querySelectorAll(".rx-rows > li")].map((e) => e.classList.contains("rx-next") ? "[next]" : e.querySelector(".rx-title")?.value).join("|")+ === "Learn to swim|Find a pool|Learn to dive|[next]|Run a marathon|See the northern lights"), "the new one is there at once, the field below it");+ok(await page.evaluate(() => document.activeElement?.closest(".rx-next") !== null && document.activeElement.value === ""), "and the field is empty and still focused");+ok(await until(page, () => (window.__creates ?? []).some((c) => c.title === "Learn to dive" && c.listGuid === "l3")), "it is made in the list");+ok(await until(page, () => (window.__reorders ?? []).some((r) => r.before === "b")), "and put before the reminder that followed");++// Another, typed straight on: it goes below the last.+await page.keyboard.type("Swim a mile");+await page.keyboard.press("Enter");+ok(await until(page, () => {+ const t = [...document.querySelectorAll(".rx-rows > li:not(.rx-next) .rx-title")].map((e) => e.value);+ return t.indexOf("Swim a mile") === t.indexOf("Learn to dive") + 1 && t.indexOf("Run a marathon") === t.indexOf("Swim a mile") + 1;+}), "a second goes below the first");++// Return on the empty field ends it there.+await page.keyboard.press("Enter");+ok(await until(page, () => !document.querySelector(".rx-next")), "Return on an empty one ends it");+ok(await page.evaluate(() => (window.__creates ?? []).length) === 2, "and makes nothing");++// A subtask's next is a subtask of the same reminder.+await until(page, () => document.querySelector('.rx-row[data-guid="a1"] .rx-title'));+await page.locator('.rx-row[data-guid="a1"] .rx-title').focus();+await page.keyboard.press("Enter");+ok(await until(page, () => document.activeElement?.closest(".rx-next.is-subtask") !== null), "below a subtask, the next is a subtask too");+await page.keyboard.type("Buy goggles");+await page.keyboard.press("Enter");+ok(await until(page, () => (window.__edits ?? []).some((e) => e.parentGuid === "a")), "made under the same reminder");+ok(await until(page, () => [...document.querySelectorAll(".rx-row.is-subtask .rx-title")].some((e) => e.value === "Buy goggles")), "and shown as its subtask");+await page.keyboard.press("Escape");+ok(await until(page, () => !document.querySelector(".rx-next")), "Escape ends it");++// Leaving the field with words in it adds them, and the field goes.+await page.getByLabel("Rename See the northern lights").focus();+await page.keyboard.press("Enter");+await until(page, () => document.activeElement?.closest(".rx-next") !== null);+await page.keyboard.type("Visit Iceland");+await page.mouse.click(900, 760);+ok(await until(page, () => (window.__creates ?? []).some((c) => c.title === "Visit Iceland")), "leaving the field adds what was typed");+ok(await until(page, () => !document.querySelector(".rx-next")), "and the field goes");++// In a smart list, Return goes to New Reminder at the foot, as before.+await page.locator(".rx-tile", { hasText: "Today" }).click();+await until(page, () => document.querySelector(".rx-row .rx-title"));+await page.locator(".rx-row .rx-title").first().focus();+await page.keyboard.press("Enter");+ok(await until(page, () => document.activeElement?.closest(".rx-add") !== null), "in Today, Return goes to New Reminder");++await ctx.close();+await b.close();+console.log(failures ? `\n${failures} FAILED` : "\nall passed");+process.exit(failures ? 1 : 0);diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjsindex 9191111..42590c5 100644--- a/.uiverify/stub.mjs+++ b/.uiverify/stub.mjs@@ -277,7 +277,10 @@ export function installStub({ screen, services, twoFactor, calendarFixture, notecase "reminder_create":// Kept, as Apple keeps it, with what the view implied.{- const guid = `made-${reminderItems.length}`;+ // Numbered on from the fixture, never twice: one moved away by a reorder does not+ // free its number for the next.+ window.__madeSeq = (window.__madeSeq ?? reminderItems.length - 1) + 1;+ const guid = `made-${window.__madeSeq}`;(window.__creates ??= []).push(args);reminderItems.push({ guid, listGuid: args.listGuid, title: args.title,notes: null, dueAt: args.dueAt ?? null, allDay: args.allDay ?? false, completedAt: null, priority: 0,@@ -340,8 +343,11 @@ export function installStub({ screen, services, twoFactor, calendarFixture, noteconst i = rows.findIndex((x) => x.guid === args.guid);if (i < 0) return null;const [moved] = rows.splice(i, 1);- const at = rows.findIndex((x) => x.guid === args.before);- rows.splice(at < 0 ? rows.length : at, 0, moved);+ // Put before one in the other list of rows (one made here, before a suite's own), it+ // goes into that one, so the order read back is the order asked for.+ const into = rows.some((x) => x.guid === args.before) ? rows : [reminderItems, window.__extraReminders ?? []].find((l) => l.some((x) => x.guid === args.before)) ?? rows;+ const at = into.findIndex((x) => x.guid === args.before);+ into.splice(at < 0 ? into.length : at, 0, moved);return null;}case "reminder_list_colour": {diff --git a/src/screens/RemindersView.tsx b/src/screens/RemindersView.tsxindex a10349c..fceeb31 100644--- a/src/screens/RemindersView.tsx+++ b/src/screens/RemindersView.tsx@@ -1379,6 +1379,75 @@ export function RemindersView() {}}+ /**+ * Return on a reminder in a list begins the next one right below it, as on the Mac: a new+ * row there, its title being typed. A subtask's next is a subtask of the same reminder, and+ * one in a section stays in that section. Nothing is made until something is typed.+ */+ /** The reminder the next one goes below; `was` its stand-in's id, once it has its own. */+ const [insertAfter, setInsertAfter] = useState<(Reminder & { was?: string }) | null>(null);+ const addBelow = async (typed: string, anchor: Reminder & { was?: string }, goOn: boolean) => {+ const line = typed.trim();+ if (!line || !listGuid) return;+ const said = parseReminder(line);+ const q = understood(said) ? said : null;+ const title = q ? q.title : line;+ const parentGuid = anchor.parentGuid;+ const section = sectionOf(anchor);+ const keyOf = (d: Date) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;+ const implied =+ q?.dueAt != null+ ? q.allDay+ ? { dueAt: dayToUtc(keyOf(new Date(q.dueAt * 1000))), allDay: true }+ : { dueAt: q.dueAt, allDay: false }+ : {};+ // Where it goes in the list's order: before the reminder that follows this one's block in+ // the same section, or last in it when there is none.+ const flat = threaded.map((t) => t.reminder);+ // The anchor by its id, or by its stand-in's while the list has not been read since it was made.+ const isAnchor = (x: Reminder) => x.guid === anchor.guid || (anchor.was !== undefined && x.guid === anchor.was);+ const at = flat.findIndex(isAnchor);+ const next = parentGuid || at < 0+ ? null+ : flat.slice(at + 1).find((x) => !x.parentGuid && !x.completedAt && sectionOf(x) === section && !x.guid.startsWith(STAND_IN)) ?? null;+ const standIn = `${STAND_IN}${Date.now()}`;+ // Shown in its place at once, the field going on below it for the next.+ const shown = {+ guid: standIn, listGuid, title, notes: null,+ dueAt: implied.dueAt === undefined ? null : implied.allDay ? dayToLocal(implied.dueAt) : implied.dueAt,+ allDay: implied.allDay ?? false, completedAt: null, priority: q?.priority ?? 0, flagged: false,+ parentGuid, sectionGuid: section, recurFrequency: q?.repeat?.frequency ?? null,+ recurInterval: q?.repeat?.interval ?? null, etag: null,+ } as Reminder;+ setItems((rows) => {+ const i = rows.findIndex(isAnchor);+ // After the anchor's own subtasks, where the row is drawn.+ let end = i;+ if (!parentGuid) while (end + 1 < rows.length && rows[end + 1].parentGuid === rows[i].guid) end += 1;+ return i < 0 ? [...rows, shown] : [...rows.slice(0, end + 1), shown, ...rows.slice(end + 1)];+ });+ // Return goes on to another below this one; leaving the field ends there.+ setInsertAfter(goOn ? shown : null);+ setError(null);+ try {+ const made = await api.reminderCreate(listGuid, title, implied);+ if (typeof made === "string" && made) {+ // The field below follows the real reminder once it has its id.+ setInsertAfter((was) => (was?.guid === standIn ? { ...shown, guid: made, was: standIn } : was));+ if (next) await api.reminderReorder(listGuid, made, next.guid).catch((e) => setError(messageOf(e)));+ if (section && REMINDER_DETAIL_WRITES) await remindersApi.sectionMove(listGuid, made, section).catch((e) => setError(messageOf(e)));+ if (parentGuid) await api.reminderEdit(made, listGuid, { parentGuid }).catch((e) => setError(messageOf(e)));+ if (q?.priority) await api.reminderEdit(made, listGuid, { priority: q.priority }).catch((e) => setError(messageOf(e)));+ if (q?.repeat) await api.reminderSetRepeat(made, listGuid, q.repeat).catch((e) => setError(messageOf(e)));+ }+ await readItems();+ } catch (err) {+ setItems((rows) => rows.filter((r) => r.guid !== standIn));+ setInsertAfter((was) => (was?.guid === standIn ? null : was));+ setError(messageOf(err));+ }+ };+const heading = inList? (lists.find((l) => l.guid === listGuid)?.title ?? "Reminders"): selection.type === "tag"@@ -1817,6 +1886,11 @@ export function RemindersView() {toggle, askRemove, rename, indent, outdent, flag, setNotes, setUrl, setDue, setEarly, setRepeat,tagAdd, tagRemove, setPriority, moveToList, moveToSection, openTag, setOpenGuid, reorder,foldSubtasks,+ next: (r) => {+ // Below it in a list, where its order is the list's; elsewhere, at the foot of the view.+ if (inList && !searching && !r.completedAt) setInsertAfter(r);+ else window.setTimeout(() => document.querySelector<HTMLInputElement>(".rx-add input")?.focus(), 0);+ },openMenu: (reminder, at) => setRowMenu({ reminder, at }),dragging: () => draggingRef.current,startDrag: (guid) => {@@ -2058,9 +2132,17 @@ export function RemindersView() {</h2>))}<ul className="rx-rows">- {section.rows.map(({ reminder, depth }) => {+ {section.rows.flatMap(({ reminder, depth }, i) => {const isOpen = openGuid === reminder.guid;- return (+ // The next reminder's field goes below the one Return was pressed on, after its+ // subtasks — the same field throughout, keyed apart from the rows, so a row+ // becoming real under it (its stand-in replaced) never takes what is being typed.+ const anchored = (g: string) => insertAfter !== null && (g === insertAfter.guid || g === insertAfter.was);+ const below =+ insertAfter !== null &&+ (anchored(reminder.guid) || (depth > 0 && reminder.parentGuid !== null && anchored(reminder.parentGuid))) &&+ !(section.rows[i + 1]?.reminder.parentGuid && anchored(section.rows[i + 1].reminder.parentGuid!));+ return [<ReminderRowkey={reminder.guid}reminder={reminder}@@ -2090,8 +2172,22 @@ export function RemindersView() {subtasks={isOpen ? items.filter((x) => x.parentGuid === reminder.guid).length : 0}kids={depth === 0 ? (kidsOf.get(reminder.guid) ?? 0) : 0}kidsHidden={hiddenSubtasks.has(reminder.guid)}- />- );+ />,+ ...(below && insertAfter+ ? [+ <NextReminder+ key="rx-next"+ subtask={Boolean(insertAfter.parentGuid)}+ onAdd={(text, goOn) => {+ const anchor = insertAfter;+ if (text.trim()) void addBelow(text, anchor, goOn);+ else setInsertAfter(null);+ }}+ onCancel={() => setInsertAfter(null)}+ />,+ ]+ : []),+ ];})}</ul></Fragment>@@ -2257,6 +2353,8 @@ type RowActions = {reorder: (guid: string, before: string) => Promise<unknown>;/** Fold a reminder's subtasks away under it, or open them again. */foldSubtasks: (guid: string) => void;+ /** Return on a reminder's title: begin the next one, below it. */+ next: (r: Reminder) => void;/** The reminder being dragged now, read at the moment it is asked. */dragging: () => string | null;startDrag: (guid: string) => void;@@ -2453,7 +2551,7 @@ const ReminderRow = memo(function ReminderRow({if (e.key === "Enter") {e.preventDefault();e.currentTarget.blur();- window.setTimeout(() => document.querySelector<HTMLInputElement>(".rx-add input")?.focus(), 0);+ act.current.next(reminder);} else if (e.key === "Escape") {// Back to the row, which then takes the arrows and Space.e.currentTarget.value = reminder.title;@@ -2758,6 +2856,53 @@ const ReminderRow = memo(function ReminderRow({);});+/**+ * The next reminder, being typed right below the one Return was pressed on. Return adds it and+ * goes on to another; Return or Escape on an empty one ends there, and leaving it with words+ * in it adds them.+ */+function NextReminder({ subtask, onAdd, onCancel }: { subtask: boolean; onAdd: (text: string, goOn: boolean) => void; onCancel: () => void }) {+ const done = useRef(false);+ return (+ <li className={`rx-row rx-next${subtask ? " is-subtask" : ""}`}>+ <span className="rx-tick" aria-hidden="true" />+ <div className="rx-text">+ <div className="rx-title-row">+ <input+ className="rx-title"+ autoFocus+ aria-label="New reminder"+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.preventDefault();+ const typed = e.currentTarget.value;+ // Added, and the same field goes on below it, empty, for the next.+ if (typed.trim()) e.currentTarget.value = "";+ else done.current = true;+ onAdd(typed, true);+ } else if (e.key === "Escape") {+ e.preventDefault();+ done.current = true;+ onCancel();+ }+ }}+ onBlur={(e) => {+ const field = e.currentTarget;+ // Moved down past the row just added, the field can lose the focus for a moment and+ // have it put back: only a focus that stays elsewhere is leaving it.+ window.setTimeout(() => {+ if (done.current || document.activeElement === field || !field.isConnected) return;+ done.current = true;+ onAdd(field.value, false);+ }, 0);+ }}+ />+ </div>+ </div>+ </li>+ );+}+/** Apple's twelve list colours, in its picker's order, keyed as CloudKit names them. */const LIST_COLOURS = [{ key: "red", hex: "#FF3B30" }, { key: "orange", hex: "#FF9500" }, { key: "yellow", hex: "#FFCC00" },