markdown_preview: Restore preview panes on workspace reload - #56972
Merged
smitbarmase merged 4 commits intoJun 16, 2026
Conversation
|
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'. |
Contributor
Author
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
Contributor
Author
|
CI hasnt run yet, can someone approve the workflow? assuming this is because of a first contribution |
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
force-pushed
the
markdown-preview-persist
branch
from
June 14, 2026 02:19
50f0f58 to
befb588
Compare
Member
|
I made a few fixes on top before merging.
Thanks again for working on this! |
This was referenced Jun 18, 2026
Closed
This was referenced Jul 1, 2026
This was referenced Jul 10, 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Markdown preview tabs were lost on restart because
MarkdownPreviewViewimplementsItemandSearchableItembut never opted intoSerializableItem, so the workspace serializer silently skipped it.This change adds persistence, modeled on the existing
ImageViewandEditorpatterns:persistencesubmodule storing(workspace_id, item_id, abs_path, mode)in amarkdown_previewstable.serializerecords the active editor's file path and the preview mode.deserializereopens the file as a buffer and constructs a newMarkdownPreviewViewaround it.markdown_preview::init.Untitled markdown buffers and previews whose source file no longer exists are not restored —
serializeanddeserializereturnNoneandErrrespectively, mirroringImageView.csv_previewandsvg_previewhave the sameSerializableItemdefect; left out of this PR to keep scope focused.Closes #38581
Part of #7371
Release Notes:
Self-Review Checklist:
on the no tests bit, consistent with ImageView, ComponentPreview, GitGraph, TerminalView, and every other SerializableItem impl other than Editor.