Fix name & normalize_pasted_path

This commit is contained in:
Daniel Edrisian
2025-08-21 15:46:32 -07:00
parent ae9413d8dd
commit 422cc8a4d0
2 changed files with 11 additions and 4 deletions

View File

@@ -191,7 +191,7 @@ impl ChatComposer {
let placeholder = format!("[Pasted Content {char_count} chars]");
self.textarea.insert_element(&placeholder);
self.pending_pastes.push((placeholder, pasted));
} else if self.handle_paste_image_paths(pasted.clone()) {
} else if self.handle_paste_image_path(pasted.clone()) {
self.textarea.insert_str(" ");
} else {
self.textarea.insert_str(&pasted);
@@ -201,7 +201,7 @@ impl ChatComposer {
true
}
pub fn handle_paste_image_paths(&mut self, pasted: String) -> bool {
pub fn handle_paste_image_path(&mut self, pasted: String) -> bool {
let Some(path_buf) = normalize_pasted_path(&pasted) else {
return false;
};

View File

@@ -14,8 +14,7 @@ pub fn normalize_pasted_path(pasted: &str) -> Option<PathBuf> {
return parts.into_iter().next().map(PathBuf::from);
}
// simple quoted path fallback
Some(PathBuf::from(pasted.trim_matches('"')))
None
}
pub fn get_img_format_label(path: PathBuf) -> String {
@@ -71,6 +70,14 @@ mod tests {
assert_eq!(result, PathBuf::from(r"C:\Users\Alice\My File.jpeg"));
}
#[test]
fn normalize_multiple_tokens_returns_none() {
// Two tokens after shell splitting → not a single path
let input = "/home/user/a\\ b.png /home/user/c.png";
let result = normalize_pasted_path(input);
assert!(result.is_none());
}
#[test]
fn img_format_label_png_jpeg_unknown() {
assert_eq!(get_img_format_label(PathBuf::from("/a/b/c.PNG")), "PNG");