Repository navigation
feat(markdown): expand Mermaid diagrams into the pan and zoom viewer everywhere - #36575
Conversation
…everywhere they render Markdown preview, the rich editor and .mmd/.mermaid files now get the same expand button that comment diagrams already had. Co-Authored-By: Claude <[email protected]>
Findings
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
03d1b131-7bbc-4f8a-a00d-dc721dfac39a
Files selected for processing: 5-
src/renderer/src/components/editor/MermaidViewer.tsxsrc/renderer/src/components/editor/RichMarkdownCodeBlock.tsxsrc/renderer/src/components/editor/use-markdown-preview-components.tsxsrc/renderer/src/components/editor/use-mermaid-diagram-expand.tssrc/renderer/src/components/sidebar/CommentMermaidBlock.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
| content={String(children).trimEnd()} | ||
| isDark={isDark} | ||
| htmlLabels={false} | ||
| onExpand={expandMermaidDiagram} |
There was a problem hiding this comment.
Keep the expand button clear of the copy button.
The pre renderer receives a code component, so its child.type === MermaidBlock check does not match. The diagram remains inside CodeBlockCopyButton, whose copy button overlaps the new expand button at the upper-right corner. Adjust the wrapper or button positions so both controls can be clicked. (raw.githubusercontent.com)
Adapt upstream stablyai#36575 with the existing diagram modal. Verify preview, rich text and diagram files in hidden Electron renderers in both themes. (cherry picked from commit 51e183a)
ELI5
Mermaid diagrams in markdown files now have an expand button, the same one comment diagrams already had. Clicking it opens the diagram full-window, where you can zoom and drag it around.
What Changed
Before: only Mermaid diagrams in comments could be expanded. Diagrams in the markdown preview, the rich editor, and
.mmd/.mermaidfiles were stuck at the width of the pane.After: every rendered Mermaid diagram shows the expand button and opens in the existing
diagram-viewermodal (DiagramViewerModal→PanZoomImageDialog). Zoom is wheel/pinch at the cursor, panning is drag, and Fit is on the toolbar.Mechanism: a small
useMermaidDiagramExpand()hook opens the modal, and is passed asonExpandtoMermaidBlockin the markdown preview,RichMarkdownCodeBlock,MermaidViewerandCommentMermaidBlock. No new viewer code.Why
#24189 built a second full-window viewer for this. We already ship one for comments and native chat, so this connects the remaining surfaces to it instead.
Linked Issue
Fixes #8731
Fixes #22372
Fixes #18467
Visual Proof
notes.md→ expand on the diagram:(screenshot removed: contained real product data)
Before: no expand button on markdown diagrams (see #22372).
Testing
Dev build (macOS): opened a markdown file with a Mermaid block and expanded it through the real button, which opened the viewer dialog.
MermaidBlock.test.tsx,MermaidViewer.test.tsx,pnpm tc.I manually tested these changes locally
Automated tests added/updated, or explained why not below: the existing
MermaidBlocktests cover the expand button; this PR only passes the handler in more places.Review