Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project_panel: Wrap filenames in code spans in confirmation dialogs (#53068)
Sudarshf964172a6977
diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex ef1981db60c..059f0685078 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -2350,7 +2350,7 @@ impl ProjectPanel {let file_name = entry.path.file_name()?.to_string();let answer = if !action.skip_prompt {- let prompt = format!("Discard changes to {}?", file_name);+ let prompt = format!("Discard changes to {}?", MarkdownInlineCode(&file_name));Some(window.prompt(PromptLevel::Info, &prompt, None, &["Restore", "Cancel"], cx))} else {None@@ -2570,7 +2570,7 @@ impl ProjectPanel {.iter().map(|(_, _, path)| MarkdownInlineCode(path).to_string()).take(CUTOFF_POINT)- .collect::<Vec<_>>();+ .collect::<Vec<String>>();paths.truncate(CUTOFF_POINT);if truncated_path_counts == 1 {paths.push(".. 1 file not shown".into());@@ -4541,7 +4541,7 @@ impl ProjectPanel {"already exists in the destination folder. ","Do you want to replace it?"),- filename+ MarkdownInlineCode(filename));let answer = cx.update(|window, cx| {diff --git a/crates/project_panel/src/project_panel_tests.rs b/crates/project_panel/src/project_panel_tests.rsindex d1a0f3b209e..3e4e3788da7 100644--- a/crates/project_panel/src/project_panel_tests.rs+++ b/crates/project_panel/src/project_panel_tests.rs@@ -11060,3 +11060,41 @@ async fn test_delete_prompt_escapes_markdown_in_file_name(cx: &mut gpui::TestApp"Are you sure you want to permanently delete `__somefile__`?");}++#[gpui::test]+async fn test_restore_file_prompt_escapes_markdown_in_file_name(cx: &mut gpui::TestAppContext) {+ init_test(cx);++ let fs = FakeFs::new(cx.executor());+ fs.insert_tree(+ path!("/root"),+ json!({+ ".git": {},+ "__init__.py": "modified contents",+ }),+ )+ .await;+ fs.set_head_and_index_for_repo(+ path!("/root/.git").as_ref(),+ &[("__init__.py", "original contents".into())],+ );++ let project = Project::test(fs.clone(), [path!("/root").as_ref()], cx).await;+ let window = cx.add_window(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));+ let workspace = window+ .read_with(cx, |mw, _| mw.workspace().clone())+ .unwrap();+ let cx = &mut VisualTestContext::from_window(window.into(), cx);+ let panel = workspace.update_in(cx, ProjectPanel::new);+ cx.run_until_parked();++ select_path(&panel, "root/__init__.py", cx);+ panel.update_in(cx, |panel, window, cx| {+ panel.restore_file(&git::RestoreFile { skip_prompt: false }, window, cx)+ });+ let (message, _detail) = cx+ .pending_prompt()+ .expect("restore should show a confirmation prompt");++ assert_eq!(message, "Discard changes to `__init__.py`?");+}diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex ea3091a6fff..55736c0824b 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -50,7 +50,8 @@ use ui::{Tooltip, prelude::*, right_click_menu,};use util::{- ResultExt, debug_panic, maybe, paths::PathStyle, serde::default_true, truncate_and_remove_front,+ ResultExt, debug_panic, markdown::MarkdownInlineCode, maybe, paths::PathStyle,+ serde::default_true, truncate_and_remove_front,};/// A selected entry in e.g. project panel.@@ -4891,15 +4892,20 @@ impl NavHistoryState {}fn dirty_message_for(buffer_path: Option<ProjectPath>, path_style: PathStyle) -> String {- let path = buffer_path- .as_ref()- .and_then(|p| {- let path = p.path.display(path_style);- if path.is_empty() { None } else { Some(path) }- })- .unwrap_or("This buffer".into());- let path = truncate_and_remove_front(&path, 80);- format!("{path} contains unsaved edits. Do you want to save it?")+ let path = buffer_path.as_ref().and_then(|p| {+ let path = p.path.display(path_style);+ if path.is_empty() { None } else { Some(path) }+ });+ match path {+ Some(path) => {+ let path = truncate_and_remove_front(&path, 80);+ format!(+ "{} contains unsaved edits. Do you want to save it?",+ MarkdownInlineCode(path.as_str())+ )+ }+ None => "This buffer contains unsaved edits. Do you want to save it?".to_string(),+ }}pub fn tab_details(items: &[Box<dyn ItemHandle>], _window: &Window, cx: &App) -> Vec<usize> {@@ -9093,6 +9099,22 @@ mod tests {}}+ #[test]+ fn test_dirty_message_for_escapes_markdown_in_path() {+ let project_path = ProjectPath {+ worktree_id: WorktreeId::from_usize(0),+ path: util::rel_path::rel_path("dir/__init__.py").into(),+ };+ assert_eq!(+ dirty_message_for(Some(project_path), PathStyle::Posix),+ "`dir/__init__.py` contains unsaved edits. Do you want to save it?"+ );+ assert_eq!(+ dirty_message_for(None, PathStyle::Posix),+ "This buffer contains unsaved edits. Do you want to save it?"+ );+ }+mod property_test {use super::*;use proptest::prelude::*;