From bb5e6dfd078f8e4d9ed63a7aac59a7de319bab8d Mon Sep 17 00:00:00 2001 From: Parker Loflin Date: Wed, 18 Nov 2026 05:53:08 +0000 Subject: [PATCH] project_panel: Show the empty-name error for whitespace-only names (#67125) ## Summary #38744 made the empty-name check `filename.is_empty()` inside `if !filename.is_empty()`, so it never ran. Names made only of whitespace got the leading or trailing whitespace warning instead of "File or directory name cannot be empty." The check is now `filename.trim().is_empty()`. ## Testing - `test_whitespace_only_filename_is_reported_as_empty` enters spaces as a new file's name and checks for the error. It fails without the fix. - `cargo test -p project_panel` and `./script/clippy` pass. ## 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). - [x] Tests cover the new or changed behavior. Release Notes: - Fixed the project panel showing the wrong message for whitespace-only file names --------- Co-authored-by: Smit Barmase --- crates/project_panel/src/project_panel.rs | 4 +-- .../project_panel/src/project_panel_tests.rs | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index cc8b23d2a0e..52cd7bc9fcd 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -2073,14 +2073,14 @@ impl ProjectPanel { }; let filename = self.filename_editor.read(cx).text(cx); if !filename.is_empty() { - if filename.is_empty() { + let trimmed_filename = filename.trim(); + if trimmed_filename.is_empty() { edit_state.validation_state = ValidationState::Error("File or directory name cannot be empty.".to_string()); cx.notify(); return; } - let trimmed_filename = filename.trim(); if trimmed_filename != filename { edit_state.validation_state = ValidationState::Warning( "File or directory name contains leading or trailing whitespace.".to_string(), diff --git a/crates/project_panel/src/project_panel_tests.rs b/crates/project_panel/src/project_panel_tests.rs index d995cd66404..084c9188f76 100644 --- a/crates/project_panel/src/project_panel_tests.rs +++ b/crates/project_panel/src/project_panel_tests.rs @@ -1215,7 +1215,40 @@ async fn test_editing_files(cx: &mut gpui::TestAppContext) { panel.filename_editor.update(cx, |editor, cx| { editor.set_text(" ", window, cx); }); + }); + panel.update_in(cx, |panel, window, cx| { + let validation_state = panel + .state + .edit_state + .as_ref() + .map(|edit_state| &edit_state.validation_state); + assert!( + matches!( + validation_state, + Some(ValidationState::Error(message)) + if message == "File or directory name cannot be empty." + ), + "Unexpected validation state: {validation_state:?}" + ); assert!(panel.confirm_edit(true, window, cx).is_none()); + panel.filename_editor.update(cx, |editor, cx| { + editor.set_text(" a ", window, cx); + }); + }); + panel.update_in(cx, |panel, window, cx| { + let validation_state = panel + .state + .edit_state + .as_ref() + .map(|edit_state| &edit_state.validation_state); + assert!( + matches!( + validation_state, + Some(ValidationState::Warning(message)) + if message == "File or directory name contains leading or trailing whitespace." + ), + "Unexpected validation state: {validation_state:?}" + ); panel.cancel(&menu::Cancel, window, cx); }); cx.run_until_parked();