Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
image viewer: Allow dropping images on pane (#21803)
Bennet Bo Fenner58f9301253a7
diff --git a/crates/image_viewer/src/image_viewer.rs b/crates/image_viewer/src/image_viewer.rsindex b5cd7eb6846..570948a8228 100644--- a/crates/image_viewer/src/image_viewer.rs+++ b/crates/image_viewer/src/image_viewer.rs@@ -108,10 +108,11 @@ impl Item for ImageView {params.text_color()};- let title = project_path- .path- .file_name()- .unwrap_or_else(|| project_path.path.as_os_str())+ let title = self+ .image_item+ .read(cx)+ .file+ .file_name(cx).to_string_lossy().to_string();Label::new(title)@@ -160,7 +161,7 @@ impl Item for ImageView {}fn breadcrumbs_text_for_image(project: &Project, image: &ImageItem, cx: &AppContext) -> String {- let path = image.path();+ let path = image.file.file_name(cx);if project.visible_worktrees(cx).count() <= 1 {return path.to_string_lossy().to_string();}diff --git a/crates/project/src/image_store.rs b/crates/project/src/image_store.rsindex 949e1f484e2..8ad3935eb38 100644--- a/crates/project/src/image_store.rs+++ b/crates/project/src/image_store.rs@@ -123,9 +123,17 @@ impl ProjectItem for ImageItem {let path = path.clone();let project = project.clone();- let ext = path- .path+ let worktree_abs_path = project+ .read(cx)+ .worktree_for_id(path.worktree_id, cx)?+ .read(cx)+ .abs_path();++ // Resolve the file extension from either the worktree path (if it's a single file)+ // or from the project path's subpath.+ let ext = worktree_abs_path.extension()+ .or_else(|| path.path.extension()).and_then(OsStr::to_str).map(str::to_lowercase).unwrap_or_default();