Skip to content

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

fix(editor): clear image selection on canvas click

tianma-if36952165dd72
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsx
index a60ae7b2..3116935c 100644
--- a/apps/web/src/components/EditorPane.tsx
+++ b/apps/web/src/components/EditorPane.tsx
@@ -1836,10 +1836,20 @@ const RichEditorPane = ({
);
if (clickedEmptyCanvas) {
editorCanvasInteractionVersionRef.current += 1;
- const clearedNodeSelection = Boolean(editor && clearNodeSelectionAtDocumentEnd(editor));
- if (editor && clearedNodeSelection) {
- window.requestAnimationFrame(() => editor.commands.focus());
- }
+ // This handler runs in capture phase, before ProseMirror translates the
+ // click coordinates into a selection. In a desktop WebView that later
+ // selection can map the empty area beside/below a block image back onto
+ // the image, undoing an immediate clear. Reconcile after ProseMirror's
+ // click handling has completed instead.
+ window.requestAnimationFrame(() => {
+ const activeEditor = editorRef.current;
+ if (activeEditor !== editor || !isEditorReady(activeEditor)) {
+ return;
+ }
+ if (clearNodeSelectionAtDocumentEnd(activeEditor)) {
+ activeEditor.commands.focus();
+ }
+ });
}
}
}, [editor, onOpenMemo, showEditorLinkOpenHint]);
diff --git a/tests/e2e/markdown-image-paste.spec.ts b/tests/e2e/markdown-image-paste.spec.ts
index fd6553b2..61fd17af 100644
--- a/tests/e2e/markdown-image-paste.spec.ts
+++ b/tests/e2e/markdown-image-paste.spec.ts
@@ -54,6 +54,23 @@ test("converts a pasted Markdown image line in the main Web editor", async ({ pa
await expect(image).toHaveAttribute("title", "Issue 229");
await expect(editor).not.toContainText(markdown);
+ const imageNode = editor.locator(".edgeever-image-node");
+ await image.click();
+ await expect(imageNode).toHaveClass(/(?:is-selected|ProseMirror-selectednode)/);
+ await imageNode.getByRole("button", { name: "较小" }).click();
+
+ const editorBox = await editor.boundingBox();
+ const imageBox = await imageNode.boundingBox();
+ expect(editorBox).not.toBeNull();
+ expect(imageBox).not.toBeNull();
+ await editor.click({
+ position: {
+ x: (editorBox?.width ?? 0) - 4,
+ y: (imageBox?.y ?? 0) - (editorBox?.y ?? 0) + Math.min((imageBox?.height ?? 0) / 2, 20),
+ },
+ });
+ await expect(imageNode).not.toHaveClass(/(?:is-selected|ProseMirror-selectednode)/);
+
await expect.poll(async () => {
const response = await page.request.get(`/api/v1/memos/${memo.id}`);
const body = await response.json() as { memo: { contentJson: unknown } };