Skip to content

markdown_preview: Restore preview panes on workspace reload - #56972

Merged
smitbarmase merged 4 commits into
zed-industries:mainfrom
cbedard:markdown-preview-persist
Jun 16, 2026
Merged

markdown_preview: Restore preview panes on workspace reload#56972
smitbarmase merged 4 commits into
zed-industries:mainfrom
cbedard:markdown-preview-persist

Conversation

@cbedard

@cbedard cbedard commented May 16, 2026

Copy link
Copy Markdown
Contributor

Markdown preview tabs were lost on restart because MarkdownPreviewView implements Item and SearchableItem but never opted into SerializableItem, so the workspace serializer silently skipped it.

This change adds persistence, modeled on the existing ImageView and Editor patterns:

  • Add a persistence submodule storing (workspace_id, item_id, abs_path, mode) in a markdown_previews table.
  • serialize records the active editor's file path and the preview mode. deserialize reopens the file as a buffer and constructs a new MarkdownPreviewView around it.
  • Register the item type in markdown_preview::init.

Untitled markdown buffers and previews whose source file no longer exists are not restored — serialize and deserialize return None and Err respectively, mirroring ImageView.

csv_preview and svg_preview have the same SerializableItem defect; left out of this PR to keep scope focused.

Closes #38581
Part of #7371

Release Notes:

  • Fixed Markdown preview tabs not being restored when reopening a workspace

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

on the no tests bit, consistent with ImageView, ComponentPreview, GitGraph, TerminalView, and every other SerializableItem impl other than Editor.

@cla-bot

cla-bot Bot commented May 16, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @cbedard 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 May 16, 2026
@cbedard

cbedard commented May 16, 2026

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 May 16, 2026
@cla-bot

cla-bot Bot commented May 16, 2026

Copy link
Copy Markdown

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

@cbedard

cbedard commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

CI hasnt run yet, can someone approve the workflow? assuming this is because of a first contribution

@smitbarmase smitbarmase added the area:preview/markdown Feedback for Zed's Markdown preview label May 29, 2026
Implement SerializableItem for MarkdownPreviewView so preview tabs are
restored alongside their source editors when Zed reopens a workspace.
The view's source file path and mode are persisted; on load, the file
is reopened as a buffer, wrapped in an Editor, and handed back to
MarkdownPreviewView::new.

Rebind the restored preview to the canonical workspace editor for its
buffer (via Item::added_to_workspace and a workspace event subscriber)
so cursor-driven scroll sync (EditorEvent::SelectionsChanged) continues
to work after restart and after the user closes and reopens the source
file. Match by buffer rather than by Editor entity in
find_existing_independent_preview_item_idx so the "already open" lookup
survives restoration and we don't create a duplicate preview.

Closes zed-industries#38581
@cbedard
cbedard force-pushed the markdown-preview-persist branch from 50f0f58 to befb588 Compare June 14, 2026 02:19
@smitbarmase smitbarmase self-assigned this Jun 16, 2026
@smitbarmase

Copy link
Copy Markdown
Member

I made a few fixes on top before merging.

  • A default preview opened in one split could start syncing with another split’s editor on the same file, so I kept it bound to the editor it was opened from.
  • Renaming the source file wasn’t picked up, so the tab kept the old name and we saved a stale path. That’s handled now.
  • A preview switching source editors, like a Follow preview moving to another file, wasn’t saving the new source, so it reloaded pointing at the old file. That’s fixed now.

Thanks again for working on this!

@smitbarmase
smitbarmase added this pull request to the merge queue Jun 16, 2026
Merged via the queue into zed-industries:main with commit f9a4bfd Jun 16, 2026
32 checks passed
This was referenced Jun 18, 2026
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…stries#56972)

Markdown preview tabs were lost on restart because `MarkdownPreviewView`
implements `Item` and `SearchableItem` but never opted into
`SerializableItem`, so the workspace serializer silently skipped it.

This change adds persistence, modeled on the existing `ImageView` and
`Editor` patterns:

- Add a `persistence` submodule storing `(workspace_id, item_id,
abs_path, mode)` in a `markdown_previews` table.
- `serialize` records the active editor's file path and the preview
mode. `deserialize` reopens the file as a buffer and constructs a new
`MarkdownPreviewView` around it.
- Register the item type in `markdown_preview::init`.

Untitled markdown buffers and previews whose source file no longer
exists are not restored — `serialize` and `deserialize` return `None`
and `Err` respectively, mirroring `ImageView`.

`csv_preview` and `svg_preview` have the same `SerializableItem` defect;
left out of this PR to keep scope focused.

Closes zed-industries#38581
Part of zed-industries#7371

Release Notes:

- Fixed Markdown preview tabs not being restored when reopening a
workspace

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

on the no tests bit, consistent with ImageView, ComponentPreview,
GitGraph, TerminalView, and every other SerializableItem impl other than
Editor.

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
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 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.

preview pane lost on restart

2 participants