Skip to content

Commit 29ea190

Browse files
monkey-modeAmaanBilwar
authored andcommitted
agent_ui: Fix pasted image context showing Image instead of actual filename (zed-industries#52082)
## What Fix image context mentions always showing the generic label `Image` instead of the actual filename when pasting from Finder or picking via the `+` → Image button in the Agent Panel. ## Why `insert_images_as_context` hardcoded the crease label to `MentionUri::PastedImage.name()` (`"Image"`) for every image, regardless of whether it originated from a named file. Both code paths that load images from file paths — `paste_images_as_context` and `add_images_from_picker` — discarded the filename before passing images to the shared insert function. ## Fix - `agent_ui/src/mention_set.rs`: Changed `insert_images_as_context` to accept `Vec<(gpui::Image, SharedString)>` instead of `Vec<gpui::Image>`, using the provided name as the crease label. In `paste_images_as_context`, extract `file_name()` from each path and pair it with the loaded image. Raw clipboard images (screenshots, copy from image editors) continue to use `"Image"` as there is no filename. - `agent_ui/src/message_editor.rs`: Same fix for `add_images_from_picker` — extract `file_name()` from each selected path and pass it alongside the image. Closes zed-industries#52079 ## Test Plan - [x] `cargo build -p agent_ui` compiles clean - [x] `cargo fmt --all -- --check` format check - [x] Manual verification of: - [x] Copy an image file in Finder (`Cmd+C`), paste into Agent Panel — mention shows actual filename - [x] `+` → Image → pick a file — mention shows actual filename - [x] Screenshot paste (`Cmd+Shift+4`) still shows `Image` - [x] Regular text paste still works ## Screenshots <img width="638" height="569" alt="image" src="https://github.com/user-attachments/assets/859d852c-66f6-4faa-a5fe-59bd34cd3d85" /> --- Release Notes: - Fixed image context mentions always showing `Image` instead of the actual filename when pasting from Finder or using the image picker in the Agent Panel
1 parent c890b33 commit 29ea190

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

‎crates/agent_ui/src/mention_set.rs‎

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ mod tests {
739739
/// Inserts a list of images into the editor as context mentions.
740740
/// This is the shared implementation used by both paste and file picker operations.
741741
pub(crate) async fn insert_images_as_context(
742-
images: Vec<gpui::Image>,
742+
images: Vec<(gpui::Image, SharedString)>,
743743
editor: Entity<Editor>,
744744
mention_set: Entity<MentionSet>,
745745
workspace: WeakEntity<Workspace>,
@@ -751,7 +751,7 @@ pub(crate) async fn insert_images_as_context(
751751

752752
let replacement_text = MentionUri::PastedImage.as_link().to_string();
753753

754-
for image in images {
754+
for (image, name) in images {
755755
let Some((excerpt_id, text_anchor, multibuffer_anchor)) = editor
756756
.update_in(cx, |editor, window, cx| {
757757
let snapshot = editor.snapshot(window, cx);
@@ -785,7 +785,7 @@ pub(crate) async fn insert_images_as_context(
785785
excerpt_id,
786786
text_anchor,
787787
content_len,
788-
MentionUri::PastedImage.name().into(),
788+
name.clone(),
789789
IconName::Image.path().into(),
790790
None,
791791
None,
@@ -856,10 +856,11 @@ pub(crate) fn paste_images_as_context(
856856

857857
Some(window.spawn(cx, async move |mut cx| {
858858
use itertools::Itertools;
859-
let (mut images, paths) = clipboard
859+
let default_name: SharedString = MentionUri::PastedImage.name().into();
860+
let (mut images, paths): (Vec<(gpui::Image, SharedString)>, Vec<_>) = clipboard
860861
.into_entries()
861862
.filter_map(|entry| match entry {
862-
ClipboardEntry::Image(image) => Some(Either::Left(image)),
863+
ClipboardEntry::Image(image) => Some(Either::Left((image, default_name.clone()))),
863864
ClipboardEntry::ExternalPaths(paths) => Some(Either::Right(paths)),
864865
_ => None,
865866
})
@@ -870,24 +871,32 @@ pub(crate) fn paste_images_as_context(
870871
cx.background_spawn(async move {
871872
let mut images = vec![];
872873
for path in paths.into_iter().flat_map(|paths| paths.paths().to_owned()) {
873-
let Ok(content) = async_fs::read(path).await else {
874+
let Ok(content) = async_fs::read(&path).await else {
874875
continue;
875876
};
876877
let Ok(format) = image::guess_format(&content) else {
877878
continue;
878879
};
879-
images.push(gpui::Image::from_bytes(
880-
match format {
881-
image::ImageFormat::Png => gpui::ImageFormat::Png,
882-
image::ImageFormat::Jpeg => gpui::ImageFormat::Jpeg,
883-
image::ImageFormat::WebP => gpui::ImageFormat::Webp,
884-
image::ImageFormat::Gif => gpui::ImageFormat::Gif,
885-
image::ImageFormat::Bmp => gpui::ImageFormat::Bmp,
886-
image::ImageFormat::Tiff => gpui::ImageFormat::Tiff,
887-
image::ImageFormat::Ico => gpui::ImageFormat::Ico,
888-
_ => continue,
889-
},
890-
content,
880+
let name: SharedString = path
881+
.file_name()
882+
.and_then(|n| n.to_str())
883+
.map(|s| SharedString::from(s.to_owned()))
884+
.unwrap_or_else(|| default_name.clone());
885+
images.push((
886+
gpui::Image::from_bytes(
887+
match format {
888+
image::ImageFormat::Png => gpui::ImageFormat::Png,
889+
image::ImageFormat::Jpeg => gpui::ImageFormat::Jpeg,
890+
image::ImageFormat::WebP => gpui::ImageFormat::Webp,
891+
image::ImageFormat::Gif => gpui::ImageFormat::Gif,
892+
image::ImageFormat::Bmp => gpui::ImageFormat::Bmp,
893+
image::ImageFormat::Tiff => gpui::ImageFormat::Tiff,
894+
image::ImageFormat::Ico => gpui::ImageFormat::Ico,
895+
_ => continue,
896+
},
897+
content,
898+
),
899+
name,
891900
));
892901
}
893902
images

‎crates/agent_ui/src/message_editor.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,12 @@ impl MessageEditor {
13661366
continue;
13671367
};
13681368

1369-
images.push(gpui::Image::from_bytes(format, content));
1369+
let name: gpui::SharedString = path
1370+
.file_name()
1371+
.and_then(|n| n.to_str())
1372+
.map(|s| gpui::SharedString::from(s.to_owned()))
1373+
.unwrap_or_else(|| "Image".into());
1374+
images.push((gpui::Image::from_bytes(format, content), name));
13701375
}
13711376

13721377
crate::mention_set::insert_images_as_context(

0 commit comments

Comments
 (0)