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
fix(web): require modifier click to open editor links
tianma-ifcca9ce5992bd
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsxindex 2ffed9ae..ea36b57d 100644--- a/apps/web/src/components/EditorPane.tsx+++ b/apps/web/src/components/EditorPane.tsx@@ -110,6 +110,7 @@ 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";const SUPPORTED_PASTE_IMAGE_TYPES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);const MOBILE_EDITOR_QUERY = "(max-width: 639px)";@@ -1411,7 +1412,10 @@ const RichEditorPane = ({const editor = useEditor({extensions: [- StarterKit.configure({ codeBlock: false }),+ StarterKit.configure({+ codeBlock: false,+ link: { openOnClick: false },+ }),EdgeEverCodeBlock.configure({ lowlight: codeBlockLowlight, defaultLanguage: "plaintext" }),ThemeBlock,ResizableImage.configure({@@ -1465,14 +1469,19 @@ const RichEditorPane = ({return true;},handleClick: (_view, _pos, event) => {- const target = event.target instanceof HTMLElement ? event.target.closest("a[href^='#memo=']") : null;- const memoId = parseMemoLinkHref(target?.getAttribute("href"));- if (!memoId || !onOpenMemo) {+ const target = event.target instanceof Element ? event.target.closest<HTMLAnchorElement>("a[href]") : null;+ if (!target || !shouldOpenEditorLink(event, _view.editable)) {return false;}+ const href = target.getAttribute("href");+ const memoId = parseMemoLinkHref(href);event.preventDefault();- onOpenMemo(memoId);+ if (memoId) {+ onOpenMemo?.(memoId);+ } else if (href) {+ window.open(target.href, "_blank", "noopener,noreferrer");+ }return true;},handlePaste: (_view, event) => {diff --git a/apps/web/src/lib/editor-link-click.test.mjs b/apps/web/src/lib/editor-link-click.test.mjsnew file mode 100644index 00000000..0870c97d--- /dev/null+++ b/apps/web/src/lib/editor-link-click.test.mjs@@ -0,0 +1,30 @@+import { describe, expect, test } from "bun:test";+import { shouldOpenEditorLink } from "./editor-link-click.ts";++const primaryClick = {+ button: 0,+ ctrlKey: false,+ metaKey: false,+};++describe("editor link click policy", () => {+ test("keeps a normal primary click inside an editable document", () => {+ expect(shouldOpenEditorLink(primaryClick, true)).toBe(false);+ });++ test("opens an editable link with Ctrl-click", () => {+ expect(shouldOpenEditorLink({ ...primaryClick, ctrlKey: true }, true)).toBe(true);+ });++ test("opens an editable link with Command-click", () => {+ expect(shouldOpenEditorLink({ ...primaryClick, metaKey: true }, true)).toBe(true);+ });++ test("opens a link normally in a read-only document", () => {+ expect(shouldOpenEditorLink(primaryClick, false)).toBe(true);+ });++ test("does not handle non-primary buttons", () => {+ expect(shouldOpenEditorLink({ ...primaryClick, button: 1 }, false)).toBe(false);+ });+});diff --git a/apps/web/src/lib/editor-link-click.ts b/apps/web/src/lib/editor-link-click.tsnew file mode 100644index 00000000..d2af19db--- /dev/null+++ b/apps/web/src/lib/editor-link-click.ts@@ -0,0 +1,12 @@+export type EditorLinkClick = {+ button: number;+ ctrlKey: boolean;+ metaKey: boolean;+};++export const shouldOpenEditorLink = (+ event: EditorLinkClick,+ editable: boolean+): boolean =>+ event.button === 0 &&+ (!editable || event.ctrlKey || event.metaKey);