Skip to content

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

fix(web): improve editor link opening behavior

tianma-if0b259bba48bc
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsx
index 2fcaf83f..047629af 100644
--- a/apps/web/src/components/EditorPane.tsx
+++ b/apps/web/src/components/EditorPane.tsx
@@ -141,6 +141,7 @@ import {
getStoredEditorLinkOpenMode,
resolveEditorLinkRequireModifier,
shouldOpenEditorLink,
+ shouldShowEditorLinkOpenHint,
type EditorLinkOpenMode,
} from "@/lib/editor-link-click";
import {
@@ -1405,8 +1406,7 @@ const RichEditorPane = ({
}, [cancelResourceMenuHide, isMobileViewport, showResourceMenu]);
const showEditorLinkOpenHint = useCallback((target: EventTarget | null) => {
- // Tip only when desktop + "require modifier" preference is on (default click-to-open needs no tip).
- if (!editor?.isEditable || isMobileViewport || editorLinkOpenMode !== "modifier") {
+ if (!shouldShowEditorLinkOpenHint(Boolean(editor?.isEditable), isMobileViewport, editorLinkOpenMode)) {
return;
}
@@ -1462,12 +1462,6 @@ const RichEditorPane = ({
}
}, []);
- useEffect(() => {
- if (editorLinkOpenMode !== "modifier") {
- setNoteLinkHintPosition(null);
- }
- }, [editorLinkOpenMode]);
-
useEffect(() => {
if (!noteLinkHintPosition) {
return;
@@ -4167,7 +4161,9 @@ const RichEditorPane = ({
{noteLinkHintPosition && (
<NoteLinkInteractionHint
- label={t("noteLinkPicker.openHint", { modifier: noteLinkModifier })}
+ label={editorLinkOpenMode === "modifier"
+ ? t("noteLinkPicker.openHint", { modifier: noteLinkModifier })
+ : t("noteLinkPicker.clickOpenHint", { modifier: noteLinkModifier })}
position={noteLinkHintPosition}
/>
)}
diff --git a/apps/web/src/lib/editor-link-click.test.mjs b/apps/web/src/lib/editor-link-click.test.mjs
index e90c250b..bed01baf 100644
--- a/apps/web/src/lib/editor-link-click.test.mjs
+++ b/apps/web/src/lib/editor-link-click.test.mjs
@@ -1,5 +1,9 @@
import { describe, expect, test } from "bun:test";
-import { shouldOpenEditorLink } from "./editor-link-click.ts";
+import {
+ resolveStoredEditorLinkOpenMode,
+ shouldOpenEditorLink,
+ shouldShowEditorLinkOpenHint,
+} from "./editor-link-click.ts";
const primaryClick = {
button: 0,
@@ -8,7 +12,24 @@ const primaryClick = {
};
describe("editor link click policy", () => {
- test("opens on plain primary click while editing by default", () => {
+ test("requires the modifier by default when no preference is stored", () => {
+ expect(resolveStoredEditorLinkOpenMode(null)).toBe("modifier");
+ expect(resolveStoredEditorLinkOpenMode("unsupported")).toBe("modifier");
+ });
+
+ test("preserves an explicitly stored link opening mode", () => {
+ expect(resolveStoredEditorLinkOpenMode("click")).toBe("click");
+ expect(resolveStoredEditorLinkOpenMode("modifier")).toBe("modifier");
+ });
+
+ test("shows a hover hint for both desktop link opening modes", () => {
+ expect(shouldShowEditorLinkOpenHint(true, false, "click")).toBe(true);
+ expect(shouldShowEditorLinkOpenHint(true, false, "modifier")).toBe(true);
+ expect(shouldShowEditorLinkOpenHint(true, true, "click")).toBe(false);
+ expect(shouldShowEditorLinkOpenHint(false, false, "modifier")).toBe(false);
+ });
+
+ test("opens on plain primary click when the modifier is not required", () => {
expect(shouldOpenEditorLink(primaryClick, true)).toBe(true);
expect(shouldOpenEditorLink(primaryClick, true, { requireModifier: false })).toBe(true);
});
diff --git a/apps/web/src/lib/editor-link-click.ts b/apps/web/src/lib/editor-link-click.ts
index c84b8ecd..90af7af1 100644
--- a/apps/web/src/lib/editor-link-click.ts
+++ b/apps/web/src/lib/editor-link-click.ts
@@ -8,17 +8,28 @@ export type EditorLinkClick = {
/**
* Desktop preference:
- * - `click` (default): plain primary click opens navigable links while editing
- * - `modifier`: require Ctrl/⌘ + click to open (plain click places caret)
+ * - `modifier` (default): require Ctrl/⌘ + click to open (plain click places caret)
+ * - `click`: plain primary click opens navigable links while editing
*
* Mobile always opens on primary click regardless of this preference.
*/
export type EditorLinkOpenMode = "click" | "modifier";
+export const DEFAULT_EDITOR_LINK_OPEN_MODE: EditorLinkOpenMode = "modifier";
+
+export const shouldShowEditorLinkOpenHint = (
+ editable: boolean,
+ isMobileViewport: boolean,
+ mode: EditorLinkOpenMode
+): boolean => editable && !isMobileViewport && (mode === "click" || mode === "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";
+export const resolveStoredEditorLinkOpenMode = (stored: string | null): EditorLinkOpenMode =>
+ stored === "click" || stored === "modifier" ? stored : DEFAULT_EDITOR_LINK_OPEN_MODE;
+
const readLocalStorageItem = (key: string): string | null => {
if (typeof window === "undefined") return null;
try {
@@ -30,7 +41,7 @@ const readLocalStorageItem = (key: string): string | null => {
export const getStoredEditorLinkOpenMode = (): EditorLinkOpenMode => {
const stored = readLocalStorageItem(EDITOR_LINK_OPEN_MODE_STORAGE_KEY);
- return stored === "modifier" ? "modifier" : "click";
+ return resolveStoredEditorLinkOpenMode(stored);
};
export const writeEditorLinkOpenMode = (mode: EditorLinkOpenMode) => {
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index e0673cde..97e3f302 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -180,7 +180,7 @@ export const enUS = {
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, hold Ctrl/⌘ and click to open; off (default) opens on a single click. Desktop only.",
+ linkOpenModifierDescription: "On by default: hold Ctrl/⌘ and click to open links, preventing accidental opens while editing. Turn off to use a single click. Desktop only.",
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.",
@@ -1036,6 +1036,7 @@ export const enUS = {
loading: "Searching notes...",
close: "Close note picker",
openHint: "Hold {{modifier}} and click to open the link. To open links with a single click, turn this option off in Profile → General",
+ clickOpenHint: "Click to open the link. To require {{modifier}} + click instead, turn this option on in Profile → General",
},
mobileNotebookPicker: {
title: "Switch notebook",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 948753e0..49ed3e6e 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -180,7 +180,7 @@ export const zhCN = {
imageCompressionDescription: "上传大图时在本地压缩,节省资源占用。",
imageCompressionAria: "是否压缩笔记内图片",
linkOpenModifierTitle: "编辑时用 Ctrl/⌘ + 点击打开链接",
- linkOpenModifierDescription: "开启后需按修饰键再点链接,避免误触;默认单击即可打开(仅桌面)。",
+ linkOpenModifierDescription: "默认开启:需按住 Ctrl/⌘ 再点击链接,避免编辑时误触;关闭后可单击打开(仅桌面)。",
linkOpenModifierAria: "编辑时是否需要 Ctrl 或 ⌘ 再点击才能打开链接",
syncIntervalTitle: "自动同步间隔",
syncIntervalDescription: "定期将编辑内容同步到服务器,本地草稿仍会即时保留。",
@@ -1036,6 +1036,7 @@ export const zhCN = {
loading: "正在搜索笔记...",
close: "关闭引用笔记",
openHint: "按住 {{modifier}} 点击链接即可打开。如需改为单击打开,请前往个人中心 → 常规设置关闭此选项",
+ clickOpenHint: "单击即可打开链接。如需改为按住 {{modifier}} 再点击,请前往个人中心 → 常规设置开启此选项",
},
mobileNotebookPicker: {
title: "切换笔记本",