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
Drive: Home and End with nothing selected, and folders first by Kind
Yashwanth Kamireddi68a50d5b299b
diff --git a/.uiverify/drive-ends.mjs b/.uiverify/drive-ends.mjsnew file mode 100644index 0000000..5929247--- /dev/null+++ b/.uiverify/drive-ends.mjs@@ -0,0 +1,65 @@+// Drive's Home and End with nothing selected yet go to the first and the last row, as Finder's+// do (Home used to select the last row, End the first); and by Kind, folders come first even+// beside a file with no extension at all.+//+// URL=http://localhost:4203 ENGINE=webkit node .uiverify/drive-ends.mjs+import { engine, engineName } from "./engine.mjs";+import { SERVICES, installStub, openScreen } from "./stub.mjs";+const URL = process.env.URL ?? "http://localhost:4173";+const b = await engine.launch();+let failures = 0;+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${engineName} ${m}`); if (!p) failures++; };+const ctx = await b.newContext({ viewport: { width: 1200, height: 800 } });+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, driveFixture: true });+await ctx.addInitScript(() => {+ const wrap = () => {+ const t = window.__TAURI_INTERNALS__;+ if (!t || t.__more) return;+ const inner = t.invoke;+ t.invoke = async (cmd, args) => {+ const out = await inner(cmd, args);+ if (cmd === "drive_children" && Array.isArray(out))+ return [...out, { drivewsid: "FILE::makefile", parentId: null, name: "Makefile", extension: null, kind: "FILE",+ size: 120, childCount: null, createdAt: 1700000000, modifiedAt: 1700000000, etag: null }];+ return out;+ };+ t.__more = true;+ };+ wrap(); document.addEventListener("DOMContentLoaded", wrap);+});+const page = await ctx.newPage();+page.on("pageerror", (e) => ok(false, `page error: ${e.message}`));+await page.goto(URL, { waitUntil: "networkidle" });+await openScreen(page, "Drive");+await page.waitForTimeout(400);+const names = () => page.locator("button.drive-row-hit .drive-name").allInnerTexts();+const chosen = () => page.locator('.drive-row-hit[aria-pressed="true"] .drive-name').allInnerTexts();+// Into the folder's blank space below the rows, as a click there: nothing selected.+const blank = async () => { const r = await page.locator(".drive-rows").boundingBox(); await page.mouse.click(r.x + r.width / 2, 790); };+await blank();+const all = await names();+ok((await chosen()).length === 0, "nothing is selected when the folder opens");+await page.keyboard.press("Home");+ok(JSON.stringify(await chosen()) === JSON.stringify([all[0]]), `Home selects the first row ${JSON.stringify(await chosen())} of ${JSON.stringify(all)}`);+await page.keyboard.press("End");+ok(JSON.stringify(await chosen()) === JSON.stringify([all.at(-1)]), `End selects the last ${JSON.stringify(await chosen())}`);+await page.reload({ waitUntil: "networkidle" });+await openScreen(page, "Drive");+await page.waitForTimeout(400);+await blank();+await page.keyboard.press("End");+ok(JSON.stringify(await chosen()) === JSON.stringify([(await names()).at(-1)]), `End with nothing selected selects the last row ${JSON.stringify(await chosen())}`);++await page.getByRole("button", { name: /Sort by/ }).click();+await page.getByRole("option", { name: "by Kind" }).click();+await page.waitForTimeout(200);+const byKind = await names();+const firstFile = byKind.findIndex((n) => n.includes(".") || n === "Makefile");+const lastFolder = Math.max(...["Downloads", "Keynote", "Shortcuts"].map((f) => byKind.indexOf(f)));+ok(firstFile > lastFolder, `by Kind, the folders come before every file, Makefile too ${JSON.stringify(byKind)}`);+await page.getByRole("button", { name: /Sort by/ }).click();+await page.getByRole("option", { name: "by Name" }).click();++await b.close();+console.log(failures ? `\n${failures} FAILED` : "\nall passed");+process.exit(failures ? 1 : 0);diff --git a/src/screens/DriveView.tsx b/src/screens/DriveView.tsxindex 1f58c47..828e8a1 100644--- a/src/screens/DriveView.tsx+++ b/src/screens/DriveView.tsx@@ -52,11 +52,13 @@ const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "basfunction sortItems(rows: DriveItem[], by: SortKey, reversed = false): DriveItem[] {const name = (a: DriveItem, b: DriveItem) => collator.compare(a.name, b.name);const folderFirst = (a: DriveItem, b: DriveItem) => Number(isContainer(b)) - Number(isContainer(a));- const kindOf = (i: DriveItem) => (isContainer(i) ? " " : (i.extension ?? "").toLowerCase());+ const kindOf = (i: DriveItem) => (i.extension ?? "").toLowerCase();const order: Record<SortKey, (a: DriveItem, b: DriveItem) => number> = {name: (a, b) => folderFirst(a, b) || name(a, b),date: (a, b) => folderFirst(a, b) || (b.modifiedAt ?? b.createdAt ?? 0) - (a.modifiedAt ?? a.createdAt ?? 0) || name(a, b),- kind: (a, b) => collator.compare(kindOf(a), kindOf(b)) || name(a, b),+ // Folders are a kind of their own, first: told apart by a space for an extension, they+ // sorted after a file with none at all ("Makefile", "README").+ kind: (a, b) => folderFirst(a, b) || collator.compare(kindOf(a), kindOf(b)) || name(a, b),size: (a, b) => folderFirst(a, b) || (b.size ?? 0) - (a.size ?? 0) || name(a, b),};// A second click on a heading turns the order round, as in Finder; folders stay on top.@@ -1241,10 +1243,13 @@ export function DriveView() {setPeeking(false);return;}- const step = (by: number) => {+ const step = (by: number, to?: number) => {if (rows.length === 0) return;const at = selected ? rows.findIndex((r) => r.drivewsid === selected) : -1;- const next = rows[at < 0 ? (by > 0 ? 0 : rows.length - 1) : Math.min(rows.length - 1, Math.max(0, at + by))].drivewsid;+ // Home and End go to an end whatever is selected; an arrow with nothing selected starts+ // at the end it points from. (Home with nothing selected used to land on the last row.)+ const index = to ?? (at < 0 ? (by > 0 ? 0 : rows.length - 1) : Math.min(rows.length - 1, Math.max(0, at + by)));+ const next = rows[index].drivewsid;if (e.shiftKey && selected) setPicked(run(next));else {anchor.current = next;@@ -1276,7 +1281,7 @@ export function DriveView() {step(k === "ArrowRight" ? 1 : -1);} else if (!mod && (k === "Home" || k === "End") && rows.length) {e.preventDefault();- step(k === "Home" ? -rows.length : rows.length);+ step(0, k === "Home" ? 0 : rows.length - 1);} else if (k === "Enter" && !mod && onRows && primary) {e.preventDefault();setPeeking(false);