mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
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 <heysmitbarmase@gmail.com>
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user