Skip to content

Fix squashed Mermaid diagrams in markdown preview - #61260

Merged
ChristopherBiscardi merged 2 commits into
zed-industries:mainfrom
atharvaajmera:fix/61051-mermaid-squashed
Jul 24, 2026
Merged

Fix squashed Mermaid diagrams in markdown preview#61260
ChristopherBiscardi merged 2 commits into
zed-industries:mainfrom
atharvaajmera:fix/61051-mermaid-squashed

Conversation

@atharvaajmera

@atharvaajmera atharvaajmera commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Wide Mermaid diagrams in Markdown Preview were forced through max_w_full(), so both width and height shrank to the pane and text became unreadable/blurry. There was no horizontal pan.

Markdown Preview already sets code_block_overflow_x_scroll: true for fenced code blocks. Mermaid ignored that flag.

This change gates layout on that style flag:

  • Preview (code_block_overflow_x_scroll): keep the raster at intrinsic size and enable overflow_x_scroll (with restrict_scroll_to_axis) so wide diagrams stay readable and can be panned horizontally.
  • Compact UIs (e.g. agent): keep previous max_w_full() fit-to-pane behavior.

Fixes #61051

Test plan

  • Open a markdown file with a wide ```mermaid flowchart (e.g. multi-column TB graph) in Markdown Preview
  • Confirm diagram is not crushed to pane width; text remains legible at default scale
  • Confirm horizontal scroll/pan works on the diagram without stealing vertical page scroll
  • Confirm compact surfaces that leave code_block_overflow_x_scroll off still fit diagrams to width
  • Confirm mermaid scale fence info still works (```mermaid 150)
  • Confirm Preview/Code tabs and copy button still work

Release Notes:

  • Fixed wide Mermaid diagrams in Markdown Preview being squashed and illegible

Wide diagrams were forced through max_w_full, so height shrank with
width and text became unreadable. When code_block_overflow_x_scroll is
enabled (markdown preview), keep the raster at intrinsic size and allow
horizontal scroll, matching fenced code blocks. Compact UIs still fit
to pane.

Fixes zed-industries#61051
@cla-bot

cla-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @atharvaajmera on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Jul 18, 2026
@atharvaajmera

Copy link
Copy Markdown
Contributor Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 18, 2026
@cla-bot

cla-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@ChristopherBiscardi ChristopherBiscardi added area:preview/markdown Feedback for Zed's Markdown preview area:preview/mermaid Feedback for Zed's Mermaid diagram support labels Jul 21, 2026
@ChristopherBiscardi

Copy link
Copy Markdown
Contributor

please add screenshots for visual changes

…agram scroll state

Gives each mermaid diagram's horizontal-scroll container a stable id so
scroll position doesn't get shared/reset across multiple diagrams in one
document. Also trims comment verbosity from the prior commit.
@atharvaajmera

Copy link
Copy Markdown
Contributor Author

Added screenshots showing the fix in action, using the diagram from this issue's original report.

Before (current main - diagram forced to shrink-to-fit, illegible):
previous-mermaid-render

After (this PR - diagram renders at intrinsic size with pan/scroll, matching fenced code block behavior):
fixed-mermaid-render
Also pushed a follow-
up commit that gives each diagram's scroll container a stable id (keyed on source_offset), so scroll position doesn't get shared/reset across multiple diagrams in the same document.

@ChristopherBiscardi ChristopherBiscardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me as without it wider mermaid diagrams are unreadably small with no bailout to open them any other way.

@ChristopherBiscardi
ChristopherBiscardi added this pull request to the merge queue Jul 24, 2026
@ChristopherBiscardi ChristopherBiscardi self-assigned this Jul 24, 2026
Merged via the queue into zed-industries:main with commit fd8f0cd Jul 24, 2026
37 checks passed
mdz-axo added a commit to mdz-axo/zed-kask that referenced this pull request Jul 25, 2026
Upstream changes (zed-industries/zed main, 27 commits):
- agent: Add agent.compaction_model setting for context compaction (zed-industries#60012)
- agent: Show effort selector for anthropic compatible providers (zed-industries#61579)
- acp: Update agent-client-protocol SDK to 2.0.0 (zed-industries#61570)
- client: Extract proxy handshakes into new proxy_handshake crate (zed-industries#61427)
- collab: Fix multiworkspace location out of sync bugs (zed-industries#61598)
- editor: Fix sticky header drag cancels autoscroll (zed-industries#53592)
- editor: Fix crash when copying and pasting using multiple cursors (zed-industries#61545)
- editor: Skip untitled buffers when saving a multi-buffer (zed-industries#61380)
- gpui: Fix images not being drawn with rounded corners with ObjectFit::Cover (zed-industries#61383)
- gpui: Fix deadlock in performance profiler and reenable it (zed-industries#61584)
- git_ui: Prevent Git panel bindings in repository selector (zed-industries#61282)
- language_model: Add explicit OpenAI conversation compaction and fix Anthropic compaction (zed-industries#61370)
- markdown: Fix squashed Mermaid diagrams in markdown preview (zed-industries#61260)
- Opus 5 BYOK Support (zed-industries#61596)
- repl: Show add-cell controls in empty notebooks (zed-industries#61329)
- search: Escape seeded buffer search query in regex mode (zed-industries#57748)
- settings: Fix VS Code import appending duplicate file associations (zed-industries#61355)
- settings: Split VSCode and Zed keymap files (zed-industries#61532)
- Treat blank spawn_agent session IDs as absent (zed-industries#60893)
- worktree: Reload git state when a watcher rescan covers a repository (zed-industries#61541)
- Plus 7 more minor fixes.

Merge fixes:
- crates/agent/src/thread.rs: replay_tool_call used 'message_ix' (undefined)
  after auto-merge; renamed to 'owning_message_ix' (the parameter name).
- Cargo.toml: Removed stale workspace members hkask-wallet and hkask-git-cas
  (both directories deleted in prior commits but workspace entries remained).
- kask/crates/hkask-regulation/src/wallet_manager.rs: Stubbed consume() and
  settle_rjoules() on WalletBudgetPort — these were API-key encumbrance
  operations from the deleted hkask-wallet crate; regulation tracks per-agent
  gas balances, not per-key encumbrances.
- kask/crates/hkask-regulation/src/wallet_gas_calibrator.rs: Fixed test to
  use crate::agent_wallet_store::WalletStore instead of hkask_storage::WalletStore.
- kask/crates/hkask-regulation/Cargo.toml: Added tokio macros feature to
  dev-dependencies for #[tokio::test].
- kask/crates/kask_bridge/Cargo.toml: Added futures dependency (needed by
  context_injector.rs for futures::executor::block_on).
- kask/crates/kask_bridge/src/context_injector.rs: Fixed futures_util::executor
  to futures::executor (futures-util doesn't include executor module).

Release Notes:

- N/A
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
## Summary

Wide Mermaid diagrams in Markdown Preview were forced through
`max_w_full()`, so both width and height shrank to the pane and text
became unreadable/blurry. There was no horizontal pan.

Markdown Preview already sets `code_block_overflow_x_scroll: true` for
fenced code blocks. Mermaid ignored that flag.

This change gates layout on that style flag:

- **Preview** (`code_block_overflow_x_scroll`): keep the raster at
intrinsic size and enable `overflow_x_scroll` (with
`restrict_scroll_to_axis`) so wide diagrams stay readable and can be
panned horizontally.
- **Compact UIs** (e.g. agent): keep previous `max_w_full()` fit-to-pane
behavior.

Fixes zed-industries#61051

## Test plan

- [ ] Open a markdown file with a wide ` ```mermaid ` flowchart (e.g.
multi-column TB graph) in Markdown Preview
- [ ] Confirm diagram is not crushed to pane width; text remains legible
at default scale
- [ ] Confirm horizontal scroll/pan works on the diagram without
stealing vertical page scroll
- [ ] Confirm compact surfaces that leave `code_block_overflow_x_scroll`
off still fit diagrams to width
- [ ] Confirm mermaid scale fence info still works (` ```mermaid 150 `)
- [ ] Confirm Preview/Code tabs and copy button still work

---

Release Notes:

- Fixed wide Mermaid diagrams in Markdown Preview being squashed and
illegible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:preview/markdown Feedback for Zed's Markdown preview area:preview/mermaid Feedback for Zed's Mermaid diagram support cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mermaid diagrams rendering squashed and unreadable in Markdown Preview

2 participants