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: Shift+Ctrl+U ticks a checklist item, Shift+Ctrl+N makes a folder

Yashwanth Kamireddied90c228a903
diff --git a/.uiverify/notes-search-marks.mjs b/.uiverify/notes-search-marks.mjs
new file mode 100644
index 0000000..2da4138
--- /dev/null
+++ b/.uiverify/notes-search-marks.mjs
@@ -0,0 +1,75 @@
+// Notes' search as on a Mac: each result previews the line its words are in, the words marked
+// in yellow there and in its title, and the note opened from it marks them too — gone once the
+// search is left. Each row is one element. Shift+Ctrl+N makes a folder; Shift+Ctrl+U ticks the
+// checklist item the cursor is in.
+// BASE=http://localhost:4173 ENGINE=webkit node .uiverify/notes-search-marks.mjs
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub } from "./stub.mjs";
+
+const BASE = process.env.BASE ?? "http://localhost:4173";
+const b = await engine.launch();
+let failures = 0;
+const ok = (pass, yes, no) => { console.log(pass ? `PASS ${yes}` : `FAIL ${no}`); if (!pass) failures++; };
+const until = (page, fn, arg) => page.waitForFunction(fn, arg, { timeout: 8000, polling: "raf" }).then(() => true, () => false);
+
+const ctx = await b.newContext({ viewport: { width: 1280, height: 820 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null,
+ calendarFixture: false, notesFixture: true, contactsFixture: false, driveFixture: false, remindersFixture: false });
+const page = await ctx.newPage();
+page.on("pageerror", (e) => ok(false, "", `page error: ${e.message}`));
+await page.goto(BASE, { waitUntil: "networkidle" });
+await page.locator(".nav-item", { hasText: "Notes" }).click();
+await page.locator(".note-row").first().waitFor();
+
+// One element a row: the option itself sits in its section's group, with no box around it.
+const shape = await page.evaluate(() => [...document.querySelectorAll(".note-row")].map((r) => r.parentElement?.getAttribute("role")));
+ok(shape.length > 0 && shape.every((r) => r === "group"), "each note row is a single element in its group", `row parents: ${shape}`);
+
+// Searched for a word deep in a note: the row shows that line, the word marked.
+await page.keyboard.press("Control+Shift+f");
+await page.keyboard.type("clock");
+ok(await until(page, () => document.querySelectorAll(".note-row").length === 1), "the search finds the one note", "search did not narrow");
+const snippet = await page.locator(".note-row .note-row-snippet").first().innerText();
+ok(snippet.includes("wall clock"), "its preview is the line the word is in", `preview: ${snippet}`);
+ok(await page.locator(".note-row .note-row-snippet mark.note-found").first().innerText() === "clock", "the word is marked in the preview", "no mark in the preview");
+
+// Opened from the result, the note marks it too.
+await page.locator(".note-row").first().click();
+ok(await until(page, () => [...document.querySelectorAll(".note-rich .note-found")].some((m) => m.textContent === "clock")),
+ "the note opened from it marks the word", "no mark in the note");
+// Marks are drawn, never written: nothing was saved for them.
+ok(await page.evaluate(() => (window.__noteSaves ?? []).length) === 0, "and marking it saves nothing", "a save went out for a mark");
+
+// A word that begins a title is marked there, from where it starts, as the index matches it.
+await page.getByLabel("Search notes").fill("curt");
+ok(await until(page, () => document.querySelector(".note-row .note-row-name mark.note-found")?.textContent === "Curt"),
+ "a title's matching start is marked", "no mark in the title");
+
+// Leaving the search takes the marks out of the note.
+await page.getByLabel("Search notes").fill("");
+ok(await until(page, () => document.querySelector(".note-rich") && !document.querySelector(".note-rich .note-found")),
+ "leaving the search clears the marks from the note", "marks stayed after the search");
+
+// Shift+Ctrl+U on a checklist item ticks it — or unticks one already ticked.
+await page.locator(".note-row", { hasText: "Curtains" }).click();
+await until(page, () => document.querySelector('.note-rich p[data-style="103"]'));
+const ticked = () => page.evaluate(() => document.querySelector('.note-rich p[data-style="103"]')?.getAttribute("data-checked") === "true");
+const was = await ticked();
+await page.locator('.note-rich p[data-style="103"]').click({ position: { x: 120, y: 8 } });
+await page.keyboard.press("Control+Shift+u");
+ok(await until(page, (w) => (document.querySelector('.note-rich p[data-style="103"]')?.getAttribute("data-checked") === "true") !== w, was),
+ "Shift+Ctrl+U ticks or unticks the checklist item", "the item stayed as it was");
+await page.keyboard.press("Control+Shift+u");
+ok(await until(page, (w) => (document.querySelector('.note-rich p[data-style="103"]')?.getAttribute("data-checked") === "true") === w, was),
+ "and again puts it back", "a second press did not put it back");
+
+// Shift+Ctrl+N: a new folder, ready to be named.
+await page.locator(".note-row", { hasText: "Curtains" }).focus();
+await page.keyboard.press("Control+Shift+n");
+ok(await until(page, () => (window.__folderCalls ?? []).some((c) => c[0] === "create")), "Shift+Ctrl+N makes a new folder", "no folder was made");
+ok(await until(page, () => document.activeElement?.classList.contains("notes-folder-rename")), "and its name is ready to type", "the name field did not take focus");
+
+await ctx.close();
+await b.close();
+console.log(failures ? `\n${failures} FAILED` : "\nall passed");
+process.exit(failures ? 1 : 0);
diff --git a/src/components/ShortcutsSheet.tsx b/src/components/ShortcutsSheet.tsx
index 1acaf5a..286bcf1 100644
--- a/src/components/ShortcutsSheet.tsx
+++ b/src/components/ShortcutsSheet.tsx
@@ -23,11 +23,12 @@ export const SHORTCUTS: { app: string; key: string; rows: Row[] }[] = [
app: "Notes",
key: "notes",
rows: [
- [[["Ctrl", "N"]], "New note"],
+ [[["Ctrl", "N"], ["Ctrl", "Shift", "N"]], "New note / new folder"],
[[["Ctrl", "F"], ["Ctrl", "Shift", "F"]], "Search this folder / all notes"],
[[["↑"], ["↓"]], "Previous / next note"],
[[["Ctrl", "Delete"]], "Delete note"],
[[["Ctrl", "S"]], "Finish editing"],
+ [[["Ctrl", "Shift", "L"], ["Ctrl", "Shift", "U"]], "Checklist / tick the item"],
],
},
{
diff --git a/src/screens/NotesView.tsx b/src/screens/NotesView.tsx
index d2761b4..8b894e2 100644
--- a/src/screens/NotesView.tsx
+++ b/src/screens/NotesView.tsx
@@ -1104,8 +1104,8 @@ export function NotesView() {
// The keys, as Notes on a Mac has them (Ctrl here). Only while Notes is the screen in front,
// and never over a sheet or a menu, which answer their own keys.
- const keys = useRef({ create, find, removeAsked, step, leaveSearch, searching });
- keys.current = { create, find, removeAsked, step, leaveSearch, searching };
+ const keys = useRef({ create, find, removeAsked, step, leaveSearch, searching, newFolder });
+ keys.current = { create, find, removeAsked, step, leaveSearch, searching, newFolder };
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (!live.current || e.defaultPrevented || e.isComposing) return;
@@ -1118,6 +1118,10 @@ export function NotesView() {
if (mod && !e.shiftKey && k === "n") {
e.preventDefault();
if (!e.repeat) void k_.create();
+ } else if (mod && e.shiftKey && k === "n") {
+ // New Folder, as Shift-Command-N makes one on a Mac: ready to be named.
+ e.preventDefault();
+ if (!e.repeat) void k_.newFolder(null);
} else if (mod && k === "f") {
e.preventDefault();
k_.find(e.shiftKey ? "all" : "folder");
diff --git a/src/screens/notes/NoteEditor.tsx b/src/screens/notes/NoteEditor.tsx
index 1e48b9d..f9d212a 100644
--- a/src/screens/notes/NoteEditor.tsx
+++ b/src/screens/notes/NoteEditor.tsx
@@ -818,6 +818,7 @@ export const NoteEditor = forwardRef<EditorHandle, Props>(function NoteEditor(
"Mod-Shift-8": restyle(STYLE.dashed),
"Mod-Shift-9": restyle(STYLE.numbered),
"Mod-Shift-l": (s, d) => toggleChecklistCmd(s, d),
+ "Mod-Shift-u": tickSelected,
}),
keymap(baseKeymap),
],
@@ -929,28 +930,7 @@ export const NoteEditor = forwardRef<EditorHandle, Props>(function NoteEditor(
const node = vw.state.doc.nodeAt(pos);
if (!node) return false;
event.preventDefault();
- const checked = !node.attrs.checked;
- const tr = vw.state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, checked });
- // With "Sort Checked Items Automatically" on, the item goes where Notes sorts it, in
- // the same edit, so one undo puts both back.
- if (moveCheckedOn()) {
- const starts: number[] = [];
- vw.state.doc.forEach((_, offset) => starts.push(offset));
- const move = checklistMove(vw.state.doc, starts.indexOf(pos), checked);
- if (move) {
- const at = (i: number) => (i < starts.length ? starts[i] : vw.state.doc.content.size);
- const slice = tr.doc.slice(at(move.from), at(move.to));
- const target = tr.mapping.map(at(move.before));
- if (move.before > move.from) {
- tr.insert(target, slice.content);
- tr.delete(at(move.from), at(move.to));
- } else {
- tr.delete(at(move.from), at(move.to));
- tr.insert(target, slice.content);
- }
- }
- }
- vw.dispatch(tr);
+ vw.dispatch(tickLine(vw.state, pos, !node.attrs.checked));
return true;
},
},
@@ -1161,6 +1141,56 @@ function steady(v: EditorView): ((mapping: Transaction["mapping"]) => void) | nu
};
}
+/**
+ * A checklist item ticked or unticked, as one edit. With "Sort Checked Items Automatically"
+ * on, the item goes where Notes sorts it in the same edit, so one undo puts both back.
+ */
+function tickLine(state: EditorState, pos: number, checked: boolean): Transaction {
+ const node = state.doc.nodeAt(pos)!;
+ const tr = state.tr.setNodeMarkup(pos, undefined, { ...node.attrs, checked });
+ if (moveCheckedOn()) {
+ const starts: number[] = [];
+ state.doc.forEach((_, offset) => starts.push(offset));
+ const move = checklistMove(state.doc, starts.indexOf(pos), checked);
+ if (move) {
+ const at = (i: number) => (i < starts.length ? starts[i] : state.doc.content.size);
+ const slice = tr.doc.slice(at(move.from), at(move.to));
+ const target = tr.mapping.map(at(move.before));
+ if (move.before > move.from) {
+ tr.insert(target, slice.content);
+ tr.delete(at(move.from), at(move.to));
+ } else {
+ tr.delete(at(move.from), at(move.to));
+ tr.insert(target, slice.content);
+ }
+ }
+ }
+ return tr;
+}
+
+/**
+ * Mark as Checked (Shift-Command-U on a Mac): the checklist items the cursor or selection is
+ * in ticked — or, when every one is ticked already, unticked. Lines that are not checklist
+ * items are left as they are; the key does nothing outside a checklist.
+ */
+const tickSelected: Command = (state, dispatch) => {
+ const items = linesIn(state).filter(({ node }) => node.attrs.style === STYLE.checklist);
+ if (!items.length) return false;
+ const checked = !items.every(({ node }) => node.attrs.checked);
+ if (!dispatch) return true;
+ // One line goes through the same tick a click on its circle makes, sorting included.
+ if (items.length === 1) {
+ dispatch(tickLine(state, items[0].pos, checked).scrollIntoView());
+ return true;
+ }
+ const tr = state.tr;
+ for (const { node, pos } of items) {
+ if (Boolean(node.attrs.checked) !== checked) tr.setNodeMarkup(pos, undefined, { ...node.attrs, checked });
+ }
+ dispatch(tr);
+ return true;
+};
+
const toggleChecklistCmd: Command = (state, dispatch) => {
const all = linesIn(state).every(({ node }) => node.attrs.style === STYLE.checklist);
return chainCommands(restyle(all ? null : STYLE.checklist))(state, dispatch);