AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
test(web): browser tests for note focus shortcuts; Linux title default (#762)
Dariusz Korytob69707f205b7
diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex f9b1bea6..9df89f72 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -125,5 +125,5 @@ jobs:- name: Install Chromium and WebKitrun: bun run test:e2e:install- - name: Test notebook appearance and memo sort persistence- run: bun run test:e2e tests/e2e/notebook-appearance.spec.ts tests/e2e/memo-sort-preference.spec.ts+ - name: Test notebook appearance, memo sort persistence and note focus shortcuts+ run: bun run test:e2e tests/e2e/notebook-appearance.spec.ts tests/e2e/memo-sort-preference.spec.ts tests/e2e/note-focus-shortcuts.spec.tsdiff --git a/apps/web/src/components/settings/ShortcutSettingsItem.tsx b/apps/web/src/components/settings/ShortcutSettingsItem.tsxindex 170e9ad3..53f401ca 100644--- a/apps/web/src/components/settings/ShortcutSettingsItem.tsx+++ b/apps/web/src/components/settings/ShortcutSettingsItem.tsx@@ -3,7 +3,7 @@ import { RotateCcw, X } from "lucide-react";import { useTranslation } from "react-i18next";import type { ShortcutAction, ShortcutBinding, ShortcutSettings } from "@/lib/app-helpers";import {- DEFAULT_SHORTCUT_SETTINGS,+ getDefaultShortcutSettings,formatShortcutBinding,getShortcutActionOptions,getShortcutActionForEvent,@@ -233,7 +233,7 @@ export const ShortcutSettingsItem = ({ shortcutSettings, onShortcutSettingsChang}, [globalShortcut, onShortcutSettingsChange, recordingAction, shortcutActionOptions, shortcutSettings, t]);const handleResetShortcuts = () => {- onShortcutSettingsChange(DEFAULT_SHORTCUT_SETTINGS);+ onShortcutSettingsChange(getDefaultShortcutSettings());finishRecording();setCaptureMessage("");};diff --git a/apps/web/src/lib/app-helpers.test.mjs b/apps/web/src/lib/app-helpers.test.mjsindex 8ad538c5..dfe254f7 100644--- a/apps/web/src/lib/app-helpers.test.mjs+++ b/apps/web/src/lib/app-helpers.test.mjs@@ -30,6 +30,7 @@ import {formatShortcutBinding,getShortcutActionForEvent,getShortcutActionOptions,+ getDefaultShortcutSettings,isPrimaryModifierPressed,shortcutBindingFromKeyboardEvent,shortcutBindingsEqual,@@ -903,13 +904,40 @@ describe("workspace shortcut preferences", () => {)).toBeNull();});+ test("adds Shift to the Linux title default because Ctrl+Alt+T opens a terminal there", () => {+ const keyboardEvent = (key, modifiers = {}) => ({ key, code: `Key${key.toUpperCase()}`, ctrlKey: false, metaKey: false, shiftKey: false, altKey: false, ...modifiers });+ const linux = getDefaultShortcutSettings("Linux x86_64");+ expect(linux.focusTitle).toEqual({ key: "t", ctrlOrMeta: true, shift: true, alt: true });+ expect(linux.focusBody).toEqual(DEFAULT_SHORTCUT_SETTINGS.focusBody);+ expect(formatShortcutBinding(linux.focusTitle, "Linux x86_64")).toBe("Ctrl + Alt + Shift + T");+ expect(getShortcutActionForEvent(keyboardEvent("T", { ctrlKey: true, altKey: true, shiftKey: true }), linux, "Linux x86_64")).toBe("focusTitle");+ expect(getShortcutActionForEvent(keyboardEvent("t", { ctrlKey: true, altKey: true }), linux, "Linux x86_64")).toBeNull();+ expect(getDefaultShortcutSettings("CrOS x86_64").focusTitle).toEqual(linux.focusTitle);+ for (const platform of ["Win32", "MacIntel", "Linux armv8l Android"]) {+ expect(getDefaultShortcutSettings(platform)).toEqual(DEFAULT_SHORTCUT_SETTINGS);+ }+ });++ test("reads Linux defaults for actions that were never customized", () => {+ const values = installLocalStorage();+ const platform = Object.getOwnPropertyDescriptor(globalThis, "navigator");+ Object.defineProperty(globalThis, "navigator", { value: { platform: "Linux x86_64" }, configurable: true });+ try {+ expect(readShortcutSettingsPreference().focusTitle).toEqual(getDefaultShortcutSettings("Linux x86_64").focusTitle);+ values.set(SHORTCUT_SETTINGS_STORAGE_KEY, JSON.stringify({ createMemo: { key: "m", ctrlOrMeta: true, shift: false, alt: false } }));+ expect(readShortcutSettingsPreference().focusTitle).toEqual(getDefaultShortcutSettings("Linux x86_64").focusTitle);+ } finally {+ if (platform) Object.defineProperty(globalThis, "navigator", platform); else delete globalThis.navigator;+ }+ });+test("adds the focus actions to legacy settings and lists them in Settings", () => {const values = installLocalStorage();values.set(SHORTCUT_SETTINGS_STORAGE_KEY, JSON.stringify({toggleSidebar: { key: "b", ctrlOrMeta: true, shift: false, alt: false },}));const settings = readShortcutSettingsPreference();- expect(settings.focusTitle).toEqual(DEFAULT_SHORTCUT_SETTINGS.focusTitle);+ expect(settings.focusTitle).toEqual(getDefaultShortcutSettings().focusTitle);expect(settings.focusBody).toEqual(DEFAULT_SHORTCUT_SETTINGS.focusBody);expect(getShortcutActionOptions((key) => key).map((option) => option.value)).toEqual(Object.keys(DEFAULT_SHORTCUT_SETTINGS));});diff --git a/apps/web/src/lib/app-helpers.ts b/apps/web/src/lib/app-helpers.tsindex aa0862e1..0a74f774 100644--- a/apps/web/src/lib/app-helpers.ts+++ b/apps/web/src/lib/app-helpers.ts@@ -238,6 +238,15 @@ export const DEFAULT_SHORTCUT_SETTINGS: ShortcutSettings = {focusBody: { key: "b", ctrlOrMeta: true, shift: false, alt: true },};+// Linux desktops and ChromeOS open a terminal with Ctrl+Alt+T, so the title+// shortcut adds Shift there. Other platforms keep Primary+Alt+T.+const LINUX_FOCUS_TITLE_SHORTCUT: ShortcutBinding = { key: "t", ctrlOrMeta: true, shift: true, alt: true };++export const getDefaultShortcutSettings = (platform = readShortcutPlatform()): ShortcutSettings =>+ /linux|cros/i.test(platform) && !/android/i.test(platform)+ ? { ...DEFAULT_SHORTCUT_SETTINGS, focusTitle: LINUX_FOCUS_TITLE_SHORTCUT }+ : DEFAULT_SHORTCUT_SETTINGS;+const LEGACY_READING_PROTECTION_SHORTCUT: ShortcutBinding = {key: "l",ctrlOrMeta: true,@@ -658,10 +667,11 @@ const isShortcutBinding = (value: unknown): value is ShortcutBinding => {};export const readShortcutSettingsPreference = (): ShortcutSettings => {+ const defaults = getDefaultShortcutSettings();try {const rawValue = window.localStorage.getItem(SHORTCUT_SETTINGS_STORAGE_KEY);if (!rawValue) {- return DEFAULT_SHORTCUT_SETTINGS;+ return defaults;}const parsedValue = JSON.parse(rawValue) as Partial<ShortcutSettings>;@@ -673,16 +683,16 @@ export const readShortcutSettingsPreference = (): ShortcutSettings => {key: normalizeShortcutKey(storedBinding.key),ctrlOrMeta: typeof storedBinding.ctrlOrMeta === "boolean" ? storedBinding.ctrlOrMeta : false,}- : DEFAULT_SHORTCUT_SETTINGS[action];+ : defaults[action];const binding = action === "toggleReadingProtection"&& shortcutBindingsEqual(normalizedBinding, LEGACY_READING_PROTECTION_SHORTCUT)- ? DEFAULT_SHORTCUT_SETTINGS.toggleReadingProtection+ ? defaults.toggleReadingProtection: normalizedBinding;return { ...settings, [action]: binding };- }, { ...DEFAULT_SHORTCUT_SETTINGS });+ }, { ...defaults });} catch {- return DEFAULT_SHORTCUT_SETTINGS;+ return defaults;}};diff --git a/docs/changes/2026-11-02-focus-title-body-shortcuts.md b/docs/changes/2026-11-02-focus-title-body-shortcuts.mdindex c158a765..0df7fc5f 100644--- a/docs/changes/2026-11-02-focus-title-body-shortcuts.md+++ b/docs/changes/2026-11-02-focus-title-body-shortcuts.md@@ -10,7 +10,7 @@ After switching notes or searching, moving the caret to the title or the body of## Behavior-1. Defaults: `⌘⌥T` / `Ctrl+Alt+T` for the title and `⌘⌥B` / `Ctrl+Alt+B` for the body. They do not overlap the existing EdgeEver defaults or the Tiptap/CodeMirror keymaps (`Mod-Shift-B` blockquote, `Mod-Alt-1…6` headings, `Mod-Alt-C` code block).+1. Defaults: `⌘⌥T` (macOS), `Ctrl+Alt+T` (Windows) and `Ctrl+Alt+Shift+T` (Linux and ChromeOS, where `Ctrl+Alt+T` opens a terminal) for the title; `⌘⌥B` / `Ctrl+Alt+B` for the body. The platform default comes from `getDefaultShortcutSettings`, which also backs **Restore defaults**. They do not overlap the existing EdgeEver defaults or the Tiptap/CodeMirror keymaps (`Mod-Shift-B` blockquote, `Mod-Alt-1…6` headings, `Mod-Alt-C` code block).2. Both actions work from anywhere in the workspace while a text note is open, including the search field and the note list. The title action places the caret at the end of the title. The body action focuses the rich-text editor (Tiptap restores the previous caret) or the Markdown source editor, depending on the current mode; the mobile plain-text editor is handled the same way.3. Nothing happens for read-only notes (trash, reading protection), while a dialog that blocks editor shortcuts is open, or when no note is selected. Table, diagram, poster and infographic notes ignore the actions.4. The standalone desktop note window handles the same actions.@@ -20,11 +20,12 @@ After switching notes or searching, moving the caret to the title or the body ofThe change is client-only: shortcut settings stay in the existing `edgeever.shortcutSettings` local preference, and older stored settings receive the new defaults through the existing fill-in path. There is no server, database, migration, sync, installer or update change.-Risks: some Linux desktops reserve `Ctrl+Alt+T` for opening a terminal, and a browser or OS may claim one of the combinations; users can rebind them in Settings. A user who already recorded one of these combinations for another action keeps that action, because earlier actions match first. Roll back by reverting the change; older versions ignore the extra stored keys.+Risks: a browser or OS may still claim one of the combinations; users can rebind them in Settings. A user who already recorded one of these combinations for another action keeps that action, because earlier actions match first. Roll back by reverting the change; older versions ignore the extra stored keys.## Verification- Unit tests cover defaults, Windows/Linux/macOS matching (including the macOS Option character), AltGr characters not matching, fill-in for older settings and the Settings list order.+- Playwright (`tests/e2e/note-focus-shortcuts.spec.ts`, run in the existing browser CI job) for Windows, macOS and Linux platform defaults: the focused element and the title caret at the end, from the search field and from inside the Markdown editor, the rich-text and Markdown bodies, no focus change under reading protection or while the quick switcher dialog is open, and the note title and body left unchanged. Removing the read-only guard makes the spec fail.- Browser check on a local self-hosted build (Chrome, macOS): title from the search field, body in rich-text and Markdown modes, title from inside the Markdown editor, no action under reading protection, and both actions listed in Settings → Shortcuts.- `bun run typecheck`, `bun run typecheck:mobile`, `bun run lint`, `bun run build:web` and `bun run test` passed.- Windows/Linux real keyboards and the packaged desktop note window were not verified manually.diff --git a/docs/changes/2026-11-02-focus-title-body-shortcuts.zh-CN.md b/docs/changes/2026-11-02-focus-title-body-shortcuts.zh-CN.mdindex 6a05e7e0..62a31531 100644--- a/docs/changes/2026-11-02-focus-title-body-shortcuts.zh-CN.md+++ b/docs/changes/2026-11-02-focus-title-body-shortcuts.zh-CN.md@@ -10,7 +10,7 @@## 行为-1. 默认键:标题为 `⌘⌥T` / `Ctrl+Alt+T`,正文为 `⌘⌥B` / `Ctrl+Alt+B`。它们不与现有 EdgeEver 默认快捷键或 Tiptap/CodeMirror 键位冲突(`Mod-Shift-B` 引用块、`Mod-Alt-1…6` 标题、`Mod-Alt-C` 代码块)。+1. 默认键:标题为 `⌘⌥T`(macOS)、`Ctrl+Alt+T`(Windows)和 `Ctrl+Alt+Shift+T`(Linux 与 ChromeOS,那里 `Ctrl+Alt+T` 会打开终端);正文为 `⌘⌥B` / `Ctrl+Alt+B`。平台默认值来自 `getDefaultShortcutSettings`,“恢复默认”也使用它。它们不与现有 EdgeEver 默认快捷键或 Tiptap/CodeMirror 键位冲突(`Mod-Shift-B` 引用块、`Mod-Alt-1…6` 标题、`Mod-Alt-C` 代码块)。2. 打开文本笔记时,两个操作在工作区任何位置都可用,包括搜索框和笔记列表。标题操作把光标放在标题末尾;正文操作根据当前模式聚焦富文本编辑器(Tiptap 恢复之前的光标位置)或 Markdown 源码编辑器,移动端纯文本编辑器同样处理。3. 只读笔记(回收站、阅读保护)、打开会屏蔽编辑器快捷键的对话框或未选中笔记时不执行任何操作。表格、图表、海报和信息图笔记忽略这两个操作。4. 桌面端独立笔记窗口支持相同操作。@@ -20,10 +20,11 @@本次只改客户端:快捷键设置仍保存在现有本地偏好 `edgeever.shortcutSettings` 中,旧设置通过现有补全逻辑获得新默认值。不涉及服务端、数据库、迁移、同步、安装器或更新。-风险:部分 Linux 桌面把 `Ctrl+Alt+T` 保留给终端,浏览器或系统也可能占用其中某个组合,用户可在设置中改绑。已把这些组合录制给其他操作的用户保持原操作,因为排在前面的操作优先匹配。回滚只需撤销本次改动,旧版本会忽略多出的存储键。+风险:浏览器或系统仍可能占用其中某个组合,用户可在设置中改绑。已把这些组合录制给其他操作的用户保持原操作,因为排在前面的操作优先匹配。回滚只需撤销本次改动,旧版本会忽略多出的存储键。## 验证+- Playwright(`tests/e2e/note-focus-shortcuts.spec.ts`,在现有浏览器 CI 任务中运行)分别使用 Windows、macOS 与 Linux 平台默认键:验证获得焦点的元素及标题光标位于末尾(从搜索框和 Markdown 编辑器内触发)、富文本与 Markdown 正文、阅读保护下及快速切换对话框打开时焦点不变,并确认笔记标题和正文未被修改。去掉只读判断后该用例会失败。- 单元测试覆盖默认值、Windows/Linux/macOS 匹配(含 macOS Option 字符)、AltGr 字符不触发、旧设置补全以及设置列表顺序。- 在本地自托管构建上用浏览器验证(Chrome、macOS):从搜索框聚焦标题,富文本与 Markdown 模式聚焦正文,在 Markdown 编辑器内聚焦标题,阅读保护下不执行,两个操作出现在“设置 → 快捷键”中。- `bun run typecheck`、`bun run typecheck:mobile`、`bun run lint`、`bun run build:web` 和 `bun run test` 通过。diff --git a/tests/e2e/note-focus-shortcuts.spec.ts b/tests/e2e/note-focus-shortcuts.spec.tsnew file mode 100644index 00000000..30e17934--- /dev/null+++ b/tests/e2e/note-focus-shortcuts.spec.ts@@ -0,0 +1,117 @@+import { expect, test, type Locator, type Page } from "@playwright/test";++// Defaults from getDefaultShortcutSettings: Linux adds Shift to the title+// shortcut because Ctrl+Alt+T opens a terminal there.+const platforms = [+ { platform: "Win32", modifier: "Control", title: "Control+Alt+t", body: "Control+Alt+b" },+ { platform: "MacIntel", modifier: "Meta", title: "Meta+Alt+t", body: "Meta+Alt+b" },+ { platform: "Linux x86_64", modifier: "Control", title: "Control+Alt+Shift+T", body: "Control+Alt+b" },+];++const caret = (input: Locator) => input.evaluate((element: HTMLInputElement) => ({+ start: element.selectionStart,+ end: element.selectionEnd,+ length: element.value.length,+}));++const openNote = async (page: Page, title: string, memoId: string) => {+ await page.goto("/");+ const item = page.locator(`[data-memo-id="${memoId}"]`).locator("button").first();+ // Startup can restore the last notebook after the first click, so retry until the note is open.+ await expect(async () => {+ await page.getByRole("button", { name: "全部笔记", exact: true }).click();+ await page.getByPlaceholder("搜索笔记").fill(title);+ await item.click({ timeout: 3_000 });+ await expect(page.getByRole("textbox", { name: "无标题笔记" })).toHaveValue(title, { timeout: 3_000 });+ }).toPass({ timeout: 30_000 });+};++for (const { platform, modifier, title: titleShortcut, body: bodyShortcut } of platforms) {+ test.describe(`${platform} note focus shortcuts`, () => {+ test.beforeEach(async ({ page }) => {+ await page.addInitScript((value) => {+ Object.defineProperty(navigator, "platform", { get: () => value });+ }, platform);+ });++ test("moves focus to the title and body without editing the note", async ({ page }) => {+ const notebooks = await (await page.request.get("/api/v1/notebooks")).json() as {+ notebooks: Array<{ id: string }>;+ };+ const title = `Focus shortcuts ${platform} ${Date.now()}`;+ const response = await page.request.post("/api/v1/memos", {+ data: {+ notebookId: notebooks.notebooks[0]?.id,+ title,+ contentMarkdown: "First paragraph for focus.\n\nSecond paragraph.",+ },+ });+ expect(response.status()).toBe(201);+ const { memo } = await response.json() as { memo: { id: string; contentMarkdown: string; title: string } };++ try {+ await openNote(page, title, memo.id);+ const search = page.getByPlaceholder("搜索笔记");+ const titleInput = page.getByRole("textbox", { name: "无标题笔记" });+ const rich = page.locator(".ProseMirror[contenteditable='true']");+ const source = page.locator(".cm-content");+ await expect(rich).toContainText("First paragraph for focus.");+ await expect(titleInput).toHaveValue(title);++ // From the search field: title with the caret at the end, then the rich-text body.+ await search.focus();+ await page.keyboard.press(titleShortcut);+ await expect(titleInput).toBeFocused();+ expect(await caret(titleInput)).toEqual({ start: title.length, end: title.length, length: title.length });+ await page.keyboard.press(bodyShortcut);+ await expect(rich).toBeFocused();+ await expect(titleInput).toHaveValue(title);++ // Markdown source editor: title from inside the source, then back to the source.+ await page.keyboard.press(`${modifier}+/`);+ await expect(source).toBeFocused();+ await page.keyboard.press(titleShortcut);+ await expect(titleInput).toBeFocused();+ expect(await caret(titleInput)).toEqual({ start: title.length, end: title.length, length: title.length });+ await page.keyboard.press(bodyShortcut);+ await expect(source).toBeFocused();+ await page.keyboard.press(`${modifier}+/`);+ await expect(rich).toBeFocused();++ // Reading protection makes the note read-only: neither shortcut moves focus.+ // Toggle it outside the editor: the rich-text editor keeps Mod+E for inline code.+ await search.focus();+ await page.keyboard.press(`${modifier}+e`);+ await expect(titleInput).toHaveJSProperty("readOnly", true);+ await page.keyboard.press(titleShortcut);+ await expect(search).toBeFocused();+ await page.keyboard.press(bodyShortcut);+ await expect(search).toBeFocused();+ await page.keyboard.press(`${modifier}+e`);+ await expect(titleInput).toHaveJSProperty("readOnly", false);++ // A blocking dialog keeps focus.+ await page.keyboard.press(`${modifier}+o`);+ const switcher = page.getByPlaceholder("搜索笔记标题或内容…");+ await expect(switcher).toBeFocused();+ await page.keyboard.press(titleShortcut);+ await expect(switcher).toBeFocused();+ await page.keyboard.press(bodyShortcut);+ await expect(switcher).toBeFocused();+ await page.keyboard.press("Escape");+ await expect(switcher).toHaveCount(0);++ // Nothing was typed into the note.+ await expect(titleInput).toHaveValue(title);+ const saved = await (await page.request.get(`/api/v1/memos/${memo.id}`)).json() as {+ memo: { contentMarkdown: string; title: string };+ };+ expect(saved.memo.title).toBe(title);+ expect(saved.memo.contentMarkdown).toBe(memo.contentMarkdown);+ } finally {+ await page.request.delete(`/api/v1/memos/${memo.id}`);+ await page.request.delete(`/api/v1/memos/${memo.id}?permanent=1`);+ }+ });+ });+}