Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(editor): open description images on click, like comment images (MUL-8957) (#10296)
Jiayuan Zhang53221b573b98
diff --git a/packages/views/editor/attachment.test.tsx b/packages/views/editor/attachment.test.tsxindex 7a18c54f27..fe6b279dde 100644--- a/packages/views/editor/attachment.test.tsx+++ b/packages/views/editor/attachment.test.tsx@@ -254,6 +254,43 @@ describe("Attachment — image dispatch", () => {expect(onDelete).toHaveBeenCalled();});+ it("editable image opens the preview on click, like a read-only one (MUL-8957)", () => {+ renderWithQuery(+ <Attachment+ attachment={{+ kind: "url",+ url: "https://external.example/shot.png",+ filename: "",+ forceKind: "image",+ }}+ editable+ />,+ );+ const figure = document.querySelector(".image-figure") as HTMLElement;+ expect(figure.getAttribute("data-clickable")).toBe("true");+ fireEvent.click(figure);+ expect(screen.getByRole("dialog").querySelector("img")).toBeTruthy();+ });++ it("uploading image stays inert to clicks", () => {+ renderWithQuery(+ <Attachment+ attachment={{+ kind: "url",+ url: "https://external.example/shot.png",+ filename: "",+ forceKind: "image",+ uploading: true,+ }}+ editable+ />,+ );+ const figure = document.querySelector(".image-figure") as HTMLElement;+ expect(figure.hasAttribute("data-clickable")).toBe(false);+ fireEvent.click(figure);+ expect(screen.queryByRole("dialog")).toBeNull();+ });+it("url-only image resolves to a record via context and uses its id for download", () => {const att = makeRecord({filename: "from-resolver.png",diff --git a/packages/views/editor/attachment.tsx b/packages/views/editor/attachment.tsxindex c4bed378b0..d48f5fff13 100644--- a/packages/views/editor/attachment.tsx+++ b/packages/views/editor/attachment.tsx@@ -493,12 +493,12 @@ function ImageAttachmentView({}};- // Click on figure opens the preview only in non-editor / non-uploading- // surfaces — inside the editor we let ProseMirror own the click for- // selection / cursor placement and route preview through the explicit- // Maximize button. The CSS rule `.image-figure[data-clickable="true"] {- // cursor: zoom-in }` keys off this same flag for the cursor affordance.- const clickable = !editable && !uploading;+ // Click on figure opens the preview on every surface once the upload has+ // settled, editors included: an issue description is always an editor, and+ // its images must open the same way a comment's do. The CSS rule+ // `.image-figure[data-clickable="true"] { cursor: zoom-in }` keys off this+ // same flag for the cursor affordance.+ const clickable = !uploading;// An image that has not loaded has no size of its own (the figure shrinks// to it), so its box is reserved up front: from its pixel size when known,diff --git a/packages/views/editor/extensions/image-view.tsx b/packages/views/editor/extensions/image-view.tsxindex 39977b077b..4babf7d19a 100644--- a/packages/views/editor/extensions/image-view.tsx+++ b/packages/views/editor/extensions/image-view.tsx@@ -5,24 +5,42 @@** Thin wrapper around the unified `<Attachment>` dispatcher. All rendering* (figure, hover toolbar, lightbox/preview) lives there. The NodeView only- * forwards Tiptap's editor-context hints (editable, selected, deleteNode).+ * forwards Tiptap's editor-context hints (editable, selected, deleteNode) and+ * keeps a click-to-view from leaving the image selected.*/import { NodeViewWrapper } from "@tiptap/react";import type { NodeViewProps } from "@tiptap/react";+import { Selection } from "@tiptap/pm/state";import { Attachment } from "../attachment";-function ImageView({ node, editor, selected, deleteNode }: NodeViewProps) {+function ImageView({ node, editor, selected, deleteNode, getPos }: NodeViewProps) {const src = (node.attrs.src as string) || "";const alt = (node.attrs.alt as string) || "";const uploading = node.attrs.uploading as boolean;const width = (node.attrs.width as number | null) ?? undefined;const height = (node.attrs.height as number | null) ?? undefined;+ // A click on the image opens the viewer, but ProseMirror has already+ // node-selected it by then. Left selected, the first keystroke after the+ // viewer hands focus back would replace the image, so the caret moves to+ // the nearest text instead.+ const releaseSelection = () => {+ const pos = getPos();+ if (typeof pos !== "number") return;+ const { state, view } = editor;+ const $after = state.doc.resolve(pos + node.nodeSize);+ const next =+ Selection.findFrom($after, 1, true) ?? Selection.findFrom($after, -1, true);+ if (next) view.dispatch(state.tr.setSelection(next));+ };+// <Attachment> emits its own .image-node wrapper, so the NodeViewWrapper// stays unclassed — no double image-node.return (- <NodeViewWrapper>+ <NodeViewWrapper+ onClick={editor.isEditable && !uploading && src ? releaseSelection : undefined}+ ><Attachmentattachment={{kind: "url",