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.

Calendar: Mac shortcuts — Ctrl+1–4 views, Ctrl+T today, Ctrl+N new event

Yashwanth Kamireddi0ed2139dee25
diff --git a/.uiverify/calendar-keys.mjs b/.uiverify/calendar-keys.mjs
new file mode 100644
index 0000000..fe2e8df
--- /dev/null
+++ b/.uiverify/calendar-keys.mjs
@@ -0,0 +1,29 @@
+// Calendar's Mac shortcuts, Ctrl for ⌘: 1–4 switch the view, T goes to today, N starts an event.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1300, height: 850 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null, calendarFixture: true });
+const page = await ctx.newPage();
+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+await openScreen(page, "Calendar");
+await page.waitForTimeout(300);
+let failures = 0;
+const ok = (pass, msg) => { console.log(`${pass ? "PASS" : "FAIL"} ${msg}`); if (!pass) failures++; };
+for (const [key, name] of [["1", "Day"], ["2", "Week"], ["3", "Month"], ["4", "Year"]]) {
+ await page.keyboard.press(`Control+${key}`);
+ await page.waitForTimeout(200);
+ const now = await page.evaluate(() => [...document.querySelectorAll("button")].find((x) =>
+ ["Day", "Week", "Month", "Year"].includes(x.textContent.trim()) &&
+ (x.getAttribute("aria-pressed") === "true" || x.getAttribute("aria-selected") === "true" || x.className.includes("is-"))
+ )?.textContent.trim());
+ ok(now === name, `Ctrl+${key} shows ${name} [${now}]`);
+}
+await page.keyboard.press("Control+2");
+await page.waitForTimeout(200);
+await page.keyboard.press("Control+n");
+await page.waitForTimeout(400);
+ok(await page.locator(".cx-block.is-draft").count() === 1, "Ctrl+N starts a new event");
+await b.close();
+process.exitCode = failures ? 1 : 0;
diff --git a/check.sh b/check.sh
index db5e79d..0dd9099 100755
--- a/check.sh
+++ b/check.sh
@@ -48,6 +48,7 @@ step "birthdays, holidays" node .uiverify/occasions.mjs
step "drive folders" node .uiverify/drive-nav.mjs
step "birthdays in contacts" node .uiverify/contact-birthday.mjs
step "empty today" node .uiverify/reminders-empty.mjs
+step "calendar keys" node .uiverify/calendar-keys.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/screens/calendar/CalendarView.tsx b/src/screens/calendar/CalendarView.tsx
index 707d893..bf49ef5 100644
--- a/src/screens/calendar/CalendarView.tsx
+++ b/src/screens/calendar/CalendarView.tsx
@@ -339,10 +339,11 @@ export function CalendarView() {
};
/** "New event": the next whole hour on the selected day, for an hour — Apple's default. */
- const newEvent = (e: React.MouseEvent) => {
+ const newEvent = (e?: React.MouseEvent) => {
const at = new Date(selected);
at.setHours(now.getHours() + 1, 0, 0, 0);
- const button = e.currentTarget.getBoundingClientRect();
+ const button = (e?.currentTarget ?? document.querySelector('[aria-label="New event"]'))?.getBoundingClientRect()
+ ?? new DOMRect(window.innerWidth - 40, 40, 0, 0);
// Under the button, never over the toolbar; in Day and Week it moves beside the new event
// once that is drawn.
newAt(seconds(at), seconds(at) + 3600, false, { x: button.right, y: button.bottom + 32 });
@@ -367,7 +368,7 @@ export function CalendarView() {
return new Date(d.getFullYear() + by, d.getMonth(), 1);
});
- // Keyboard, as in Calendar: ⌘/Ctrl-arrows page, T goes to today, N makes an event.
+ // Keyboard, as in Calendar on a Mac (Ctrl here): arrows page, T today, 1–4 the views, N an event.
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
const typing = (e.target as HTMLElement | null)?.closest("input, textarea, select, [contenteditable]");
@@ -378,9 +379,15 @@ export function CalendarView() {
return;
}
if (typing || draft) return;
- if ((e.metaKey || e.ctrlKey) && e.key === "ArrowLeft") shift(-1);
- else if ((e.metaKey || e.ctrlKey) && e.key === "ArrowRight") shift(1);
- else if (e.key === "t" && !e.metaKey && !e.ctrlKey) setSelected(midnight(new Date()));
+ const command = (e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey;
+ const k = e.key.toLowerCase();
+ if (command && e.key === "ArrowLeft") shift(-1);
+ else if (command && e.key === "ArrowRight") shift(1);
+ // ⌘T, and the bare T this screen always had.
+ else if (k === "t" && !e.altKey && !e.shiftKey) setSelected(midnight(new Date()));
+ // ⌘1–⌘4: Day, Week, Month, Year, in the order the switch shows them.
+ else if (command && /^[1-4]$/.test(e.key)) setView(VIEWS[Number(e.key) - 1].key);
+ else if (command && k === "n") newEvent();
else return;
e.preventDefault();
};