Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(web): default click-to-open links with desktop modifier preference

tianma-if9de7455f6b5e
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsx
index a1ccfe9f..36ac3f1d 100644
--- a/apps/web/src/components/EditorPane.tsx
+++ b/apps/web/src/components/EditorPane.tsx
@@ -136,7 +136,13 @@ import { RELEASE_STATUS_EVENT } from "@/lib/release-notice";
import { downloadMarkdownFile } from "@/lib/note-markdown-export";
import { openNotePrintPreview, serializeNoteDocumentForPrint } from "@/lib/note-print";
import { isBrowserOffline } from "@/lib/network-status";
-import { shouldOpenEditorLink } from "@/lib/editor-link-click";
+import {
+ EDITOR_LINK_OPEN_MODE_CHANGED_EVENT,
+ getStoredEditorLinkOpenMode,
+ resolveEditorLinkRequireModifier,
+ shouldOpenEditorLink,
+ type EditorLinkOpenMode,
+} from "@/lib/editor-link-click";
import {
formatMarkdownLink,
insertMarkdownSnippet,
@@ -937,6 +943,27 @@ const RichEditorPane = ({
() => typeof navigator !== "undefined" && /mac|iphone|ipad|ipod/i.test(navigator.platform) ? "⌘" : "Ctrl",
[]
);
+ const [editorLinkOpenMode, setEditorLinkOpenMode] = useState<EditorLinkOpenMode>(() =>
+ getStoredEditorLinkOpenMode()
+ );
+
+ useEffect(() => {
+ const syncMode = () => setEditorLinkOpenMode(getStoredEditorLinkOpenMode());
+ const onPreferenceChanged = (event: Event) => {
+ const detail = (event as CustomEvent<EditorLinkOpenMode>).detail;
+ if (detail === "click" || detail === "modifier") {
+ setEditorLinkOpenMode(detail);
+ return;
+ }
+ syncMode();
+ };
+ window.addEventListener(EDITOR_LINK_OPEN_MODE_CHANGED_EVENT, onPreferenceChanged);
+ window.addEventListener("storage", syncMode);
+ return () => {
+ window.removeEventListener(EDITOR_LINK_OPEN_MODE_CHANGED_EVENT, onPreferenceChanged);
+ window.removeEventListener("storage", syncMode);
+ };
+ }, []);
const noteLinkResultsQuery = useQuery({
queryKey: ["memo-link-search", noteLinkQuery],
queryFn: () => repository.listMemos({ q: noteLinkQuery, limit: 20 }),
@@ -1278,7 +1305,20 @@ const RichEditorPane = ({
},
handleClick: (_view, _pos, event) => {
const target = event.target instanceof Element ? event.target.closest<HTMLAnchorElement>("a[href]") : null;
- if (!target || !shouldOpenEditorLink(event, _view.editable)) {
+ if (!target) {
+ return false;
+ }
+
+ // Attachment chips use the resource action menu — never treat as a plain hyperlink open.
+ if (getAttachmentLinkFromEventTarget(target)) {
+ return false;
+ }
+
+ // Read preference/viewport at click time so settings changes apply without remounting the editor.
+ const isMobile =
+ typeof window !== "undefined" && window.matchMedia(MOBILE_EDITOR_QUERY).matches;
+ const requireModifier = resolveEditorLinkRequireModifier(isMobile);
+ if (!shouldOpenEditorLink(event, _view.editable, { requireModifier })) {
return false;
}
@@ -1545,16 +1585,18 @@ const RichEditorPane = ({
}, [cancelResourceMenuHide, isMobileViewport]);
const showEditorLinkOpenHint = useCallback((target: EventTarget | null) => {
- // Editable mode: plain click places the caret; open requires Ctrl/⌘. Surface a tip for all links.
- if (!editor?.isEditable || isMobileViewport) {
+ // Tip only when desktop + "require modifier" preference is on (default click-to-open needs no tip).
+ if (!editor?.isEditable || isMobileViewport || editorLinkOpenMode !== "modifier") {
return;
}
const link = getEditorNavigableLinkFromEventTarget(target);
if (link) {
setNoteLinkHintPosition(getNoteLinkHintPosition(link));
+ } else {
+ setNoteLinkHintPosition(null);
}
- }, [editor?.isEditable, isMobileViewport]);
+ }, [editor?.isEditable, editorLinkOpenMode, isMobileViewport]);
const handleEditorMouseOver = useCallback((event: ReactMouseEvent<HTMLDivElement>) => {
if (showAttachmentMenu(event.target)) return;
@@ -1600,6 +1642,12 @@ const RichEditorPane = ({
}
}, []);
+ useEffect(() => {
+ if (editorLinkOpenMode !== "modifier") {
+ setNoteLinkHintPosition(null);
+ }
+ }, [editorLinkOpenMode]);
+
useEffect(() => {
if (!noteLinkHintPosition) {
return;
diff --git a/apps/web/src/components/settings/PreferenceCard.tsx b/apps/web/src/components/settings/PreferenceCard.tsx
index 5d3539ac..692f53fd 100644
--- a/apps/web/src/components/settings/PreferenceCard.tsx
+++ b/apps/web/src/components/settings/PreferenceCard.tsx
@@ -1,7 +1,13 @@
-import { ChartNoAxesCombined, Image, Languages, Palette, RefreshCw } from "lucide-react";
+import { ChartNoAxesCombined, Image, Languages, MousePointerClick, Palette, RefreshCw } from "lucide-react";
import { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { writeSyncIntervalPreference, type ShortcutSettings, type SyncIntervalPreference } from "@/lib/app-helpers";
+import {
+ EDITOR_LINK_OPEN_MODE_CHANGED_EVENT,
+ getStoredEditorLinkOpenMode,
+ writeEditorLinkOpenMode,
+ type EditorLinkOpenMode,
+} from "@/lib/editor-link-click";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
@@ -53,6 +59,7 @@ export const PreferenceCard = ({
const [editingTheme, setEditingTheme] = useState<CustomEditorTheme | null>(null);
const [activeLocalePreference, setActiveLocalePreference] = useState<AppLocalePreference>(() => getAppLocalePreference());
const [isMobile, setIsMobile] = useState(false);
+ const [linkOpenMode, setLinkOpenMode] = useState<EditorLinkOpenMode>(() => getStoredEditorLinkOpenMode());
useEffect(() => {
const mediaQuery = window.matchMedia("(max-width: 640px)");
@@ -62,6 +69,24 @@ export const PreferenceCard = ({
return () => mediaQuery.removeEventListener("change", handler);
}, []);
+ useEffect(() => {
+ const syncMode = () => setLinkOpenMode(getStoredEditorLinkOpenMode());
+ const onPreferenceChanged = (event: Event) => {
+ const detail = (event as CustomEvent<EditorLinkOpenMode>).detail;
+ if (detail === "click" || detail === "modifier") {
+ setLinkOpenMode(detail);
+ return;
+ }
+ syncMode();
+ };
+ window.addEventListener(EDITOR_LINK_OPEN_MODE_CHANGED_EVENT, onPreferenceChanged);
+ window.addEventListener("storage", syncMode);
+ return () => {
+ window.removeEventListener(EDITOR_LINK_OPEN_MODE_CHANGED_EVENT, onPreferenceChanged);
+ window.removeEventListener("storage", syncMode);
+ };
+ }, []);
+
const activeCustom = customEditorThemes.find((t) => t.id === editorTheme);
const isPreset = editorTheme === "default" || editorTheme === "minimal-emerald" || editorTheme === "outline-emerald" || editorTheme === "wechat-green" || editorTheme === "modern-mint";
@@ -279,6 +304,28 @@ export const PreferenceCard = ({
</div>
</div>
+ {/* Desktop only: mobile editors always open links on a plain tap. */}
+ <div className="hidden min-h-16 flex-col items-start gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4 lg:flex">
+ <div className="flex min-w-0 items-start gap-3">
+ <MousePointerClick className="mt-0.5 h-4 w-4 shrink-0 text-emerald-700" />
+ <div className="min-w-0">
+ <div className="text-sm font-semibold text-slate-900">{t("settings.linkOpenModifierTitle")}</div>
+ <div className="mt-0.5 text-xs leading-4 text-slate-500">{t("settings.linkOpenModifierDescription")}</div>
+ </div>
+ </div>
+ <div className="flex w-full shrink-0 justify-start sm:w-44 sm:justify-end">
+ <Switch
+ checked={linkOpenMode === "modifier"}
+ onCheckedChange={(enabled) => {
+ const next: EditorLinkOpenMode = enabled ? "modifier" : "click";
+ writeEditorLinkOpenMode(next);
+ setLinkOpenMode(next);
+ }}
+ aria-label={t("settings.linkOpenModifierAria")}
+ />
+ </div>
+ </div>
+
<div className="hidden lg:block">
<ShortcutSettingsItem
shortcutSettings={shortcutSettings}
diff --git a/apps/web/src/lib/editor-link-click.test.mjs b/apps/web/src/lib/editor-link-click.test.mjs
index 0870c97d..e90c250b 100644
--- a/apps/web/src/lib/editor-link-click.test.mjs
+++ b/apps/web/src/lib/editor-link-click.test.mjs
@@ -8,23 +8,29 @@ const primaryClick = {
};
describe("editor link click policy", () => {
- test("keeps a normal primary click inside an editable document", () => {
- expect(shouldOpenEditorLink(primaryClick, true)).toBe(false);
+ test("opens on plain primary click while editing by default", () => {
+ expect(shouldOpenEditorLink(primaryClick, true)).toBe(true);
+ expect(shouldOpenEditorLink(primaryClick, true, { requireModifier: false })).toBe(true);
});
- test("opens an editable link with Ctrl-click", () => {
- expect(shouldOpenEditorLink({ ...primaryClick, ctrlKey: true }, true)).toBe(true);
+ test("keeps a normal primary click inside an editable document when requireModifier", () => {
+ expect(shouldOpenEditorLink(primaryClick, true, { requireModifier: true })).toBe(false);
});
- test("opens an editable link with Command-click", () => {
- expect(shouldOpenEditorLink({ ...primaryClick, metaKey: true }, true)).toBe(true);
+ test("opens an editable link with Ctrl-click when requireModifier", () => {
+ expect(shouldOpenEditorLink({ ...primaryClick, ctrlKey: true }, true, { requireModifier: true })).toBe(true);
});
- test("opens a link normally in a read-only document", () => {
- expect(shouldOpenEditorLink(primaryClick, false)).toBe(true);
+ test("opens an editable link with Command-click when requireModifier", () => {
+ expect(shouldOpenEditorLink({ ...primaryClick, metaKey: true }, true, { requireModifier: true })).toBe(true);
+ });
+
+ test("opens a link normally in a read-only document even with requireModifier", () => {
+ expect(shouldOpenEditorLink(primaryClick, false, { requireModifier: true })).toBe(true);
});
test("does not handle non-primary buttons", () => {
expect(shouldOpenEditorLink({ ...primaryClick, button: 1 }, false)).toBe(false);
+ expect(shouldOpenEditorLink({ ...primaryClick, button: 1 }, true, { requireModifier: true })).toBe(false);
});
});
diff --git a/apps/web/src/lib/editor-link-click.ts b/apps/web/src/lib/editor-link-click.ts
index d2af19db..c84b8ecd 100644
--- a/apps/web/src/lib/editor-link-click.ts
+++ b/apps/web/src/lib/editor-link-click.ts
@@ -1,12 +1,82 @@
+/** Helpers for editor hyperlink click policy (desktop preference + mobile always-click). */
+
export type EditorLinkClick = {
button: number;
ctrlKey: boolean;
metaKey: boolean;
};
+/**
+ * Desktop preference:
+ * - `click` (default): plain primary click opens navigable links while editing
+ * - `modifier`: require Ctrl/⌘ + click to open (plain click places caret)
+ *
+ * Mobile always opens on primary click regardless of this preference.
+ */
+export type EditorLinkOpenMode = "click" | "modifier";
+
+export const EDITOR_LINK_OPEN_MODE_STORAGE_KEY = "edgeever.editor.linkOpenMode";
+
+export const EDITOR_LINK_OPEN_MODE_CHANGED_EVENT = "edgeever:editor-link-open-mode-changed";
+
+const readLocalStorageItem = (key: string): string | null => {
+ if (typeof window === "undefined") return null;
+ try {
+ return window.localStorage?.getItem(key) ?? null;
+ } catch {
+ return null;
+ }
+};
+
+export const getStoredEditorLinkOpenMode = (): EditorLinkOpenMode => {
+ const stored = readLocalStorageItem(EDITOR_LINK_OPEN_MODE_STORAGE_KEY);
+ return stored === "modifier" ? "modifier" : "click";
+};
+
+export const writeEditorLinkOpenMode = (mode: EditorLinkOpenMode) => {
+ if (typeof window === "undefined") return;
+ try {
+ window.localStorage?.setItem(EDITOR_LINK_OPEN_MODE_STORAGE_KEY, mode);
+ } catch {
+ // Private mode / blocked storage — preference is session-only via the event.
+ }
+ window.dispatchEvent(
+ new CustomEvent(EDITOR_LINK_OPEN_MODE_CHANGED_EVENT, { detail: mode })
+ );
+};
+
+export type ShouldOpenEditorLinkOptions = {
+ /**
+ * When true, plain click does not open while the document is editable —
+ * Ctrl/⌘ is required. When false (default product behavior), plain click opens.
+ */
+ requireModifier?: boolean;
+};
+
+/**
+ * Decide whether a primary click should open a navigable editor link.
+ * Read-only documents always open on primary click.
+ */
export const shouldOpenEditorLink = (
event: EditorLinkClick,
- editable: boolean
-): boolean =>
- event.button === 0 &&
- (!editable || event.ctrlKey || event.metaKey);
+ editable: boolean,
+ options?: ShouldOpenEditorLinkOptions
+): boolean => {
+ if (event.button !== 0) {
+ return false;
+ }
+
+ if (!editable) {
+ return true;
+ }
+
+ if (options?.requireModifier) {
+ return event.ctrlKey || event.metaKey;
+ }
+
+ return true;
+};
+
+/** Desktop only: require Ctrl/⌘ when the stored preference is `modifier`. */
+export const resolveEditorLinkRequireModifier = (isMobileViewport: boolean): boolean =>
+ !isMobileViewport && getStoredEditorLinkOpenMode() === "modifier";
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 7cd2acb1..dfd8226d 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -174,6 +174,10 @@ export const enUS = {
imageCompressionTitle: "Compress note images",
imageCompressionDescription: "Compress large images locally before upload to reduce storage use.",
imageCompressionAria: "Compress note images",
+ linkOpenModifierTitle: "Open links with Ctrl/⌘ + click while editing",
+ linkOpenModifierDescription:
+ "When on, a plain click places the caret; hold Ctrl (Windows) or ⌘ (Mac) and click to open a link, which helps avoid accidental navigation. When off (default), a single click opens the link. Desktop only; saved in this browser.",
+ linkOpenModifierAria: "Require Ctrl or ⌘ click to open links while editing",
syncIntervalTitle: "Automatic sync interval",
syncIntervalDescription: "Sync edits to the server automatically while keeping local drafts available immediately.",
syncIntervals: { "30s": "Every 30 seconds", "5m": "Every 5 minutes", "15m": "Every 15 minutes", "30m": "Every 30 minutes", "1h": "Every hour", "2h": "Every 2 hours" },
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 9f3d34f7..db447f4b 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -174,6 +174,10 @@ export const zhCN = {
imageCompressionTitle: "压缩笔记内图片",
imageCompressionDescription: "上传大图时在本地压缩,节省资源占用。",
imageCompressionAria: "是否压缩笔记内图片",
+ linkOpenModifierTitle: "编辑时用 Ctrl/⌘ + 点击打开链接",
+ linkOpenModifierDescription:
+ "开启后,编辑态下普通点击不会跳转,需按住 Ctrl(Windows)或 ⌘(Mac)再点链接,避免误触。关闭(默认)时单击即可打开。仅桌面端生效,偏好保存在当前浏览器。",
+ linkOpenModifierAria: "编辑时是否需要 Ctrl 或 ⌘ 再点击才能打开链接",
syncIntervalTitle: "自动同步间隔",
syncIntervalDescription: "定期将编辑内容同步到服务器,本地草稿仍会即时保留。",
syncIntervals: { "30s": "每 30 秒", "5m": "每 5 分钟", "15m": "每 15 分钟", "30m": "每 30 分钟", "1h": "每 1 小时", "2h": "每 2 小时" },