Manoj sk cb13b37a6d project_panel: Add SVG preview context menu item (#65539)
## Summary

Adds an **Open SVG Preview** entry to the project panel's right-click
menu for `.svg` files, mirroring the existing **Open Markdown Preview**
entry. Previously an SVG preview could only be opened from an editor
that already had the file open (#47821); now it can be opened directly
from the file tree without opening the file first.

- Added a `project_panel::OpenSvgPreview` action, shown for `.svg` files
(case-insensitive) in both the normal and read-only context menus.
- Added `SvgPreviewView::open_for_project_path`, which loads the file's
buffer through the project and opens the preview in the active pane. It
reuses `open_preview_in_pane`, so opening the preview for a file that
already has one activates the existing tab instead of adding a
duplicate.
- If the file can't be opened, the error is shown as a workspace
notification.
- Extracted the `.svg` extension check from
`SvgPreviewView::is_svg_file` into a new
`SvgPreviewView::is_svg_path(&Path)` function. The project panel only
has the selected entry's path (the file may not be open in any buffer),
so it needs a path-based check. `is_svg_file` now gets the file name
from the buffer and calls `is_svg_path`, so the editor and the project
panel use the same check. Its behavior is unchanged.

The panel uses its own action instead of reusing the global
`svg::OpenPreview`, so running "svg: open preview" from the command
palette while the project panel has focus still previews the active SVG
editor.

## Testing

Manually tested on macOS:

- Right-click an `.svg` file → **Open SVG Preview** renders the preview,
including when a non-SVG file is the active tab.
- Opening the preview again for the same file activates the existing
preview tab instead of adding a duplicate.
- The preview updates when the file is edited externally, even when no
editor for it is open.
- Uppercase extensions (`ICON.SVG`) show the entry; folders and non-SVG
files don't.
- Invalid SVG content shows the preview's error state.
- An unreadable file (`chmod 000`) shows an error notification.
- "svg: open preview" from the command palette still works while the
project panel has focus.
- Not tested: the read-only context menu (collab guest). The SVG entry
is added there the same way as the existing Markdown entry.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [x] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [ ] Tests cover the new or changed behavior - manually tested; no
automated test added.

Follow-up changes after review:

- Fixed the "Open SVG Preview" and "Open Markdown Preview" items not
appearing when a file is opened on its own (e.g. `zed icon.svg`). That
file is the worktree root, so its path is empty and the extension check
failed. The panel now falls back to the worktree's root name, which is
what it already did to label the entry.
- Moved that fallback into an `entry_file_name` helper, used by the
context menu, both preview actions, and the entry label.
- Both preview actions now resolve the selected file through the
existing `selected_file_project_path` lookup instead of building the
`ProjectPath` by hand.
- Added `test_open_svg_preview_for_single_file_worktree`.

Release Notes:

- Added an "Open SVG Preview" option to the project panel's context menu
for SVG files, and fixed the "Open Markdown Preview" option not
appearing for files opened on their own.

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
2026-10-13 13:15:34 +00:00
…
…
…
…
2026-09-11 09:13:44 +00:00
…
…
…
…

Zed

Zed CI

Welcome to Zed, a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.


Installation

On macOS, Linux, and Windows you can download Zed directly or install Zed via your local package manager (macOS/Linux/Windows).

Other platforms are not yet available:

Developing Zed

Contributing

See CONTRIBUTING.md for ways you can contribute to Zed.

Also... we're hiring! Check out our jobs page for open roles.

Licensing

Zed source code is licensed primarily under GPL-3.0-or-later, with Apache-2.0 components where marked.

License information for third party dependencies must be correctly provided for CI to pass.

We use cargo-about to automatically comply with open source licenses. If CI is failing, check the following:

  • Is it showing a no license specified error for a crate you've created? If so, add publish = false under [package] in your crate's Cargo.toml.
  • Is the error failed to satisfy license requirements for a dependency? If so, first determine what license the project has and whether this system is sufficient to comply with this license's requirements. If you're unsure, ask a lawyer. Once you've verified that this system is acceptable add the license's SPDX identifier to the accepted array in script/licenses/zed-licenses.toml.
  • Is cargo-about unable to find the license for a dependency? If so, add a clarification field at the end of script/licenses/zed-licenses.toml, as specified in the cargo-about book.

Sponsorship

Zed is developed by Zed Industries, Inc., a for-profit company.

If you’d like to financially support the project, you can do so via GitHub Sponsors. Sponsorships go directly to Zed Industries and are used as general company revenue. There are no perks or entitlements associated with sponsorship.

S
Description
No description provided
Readme 1.6 GiB
Languages
Rust 95.4%
JSON-with-Comments 2.4%
Python 0.8%
Inno Setup 0.3%
Tree-sitter Query 0.3%
Other 0.4%