Suggest language extensions for untitled buffers (#55263)

Fixes #53527.

## Summary

- Suggest `untitled.<extension>` when saving an untitled editor buffer
with a selected non-Plain Text language.
- Preserve the existing title-based suggestion for existing files, Plain
Text buffers, and buffers without a language extension.
- Add a regression test for an untitled Rust buffer suggesting
`untitled.rs`.

## Testing

- `mise exec rust@1.95.0 -- cargo fmt --check -p editor`
- `mise exec rust@1.95.0 -- cargo test -p editor
test_suggested_filename_uses_language_extension_for_untitled_buffer
--lib`

## Suggested .rules additions

None.

Release Notes:

- Fixed Save As suggestions for untitled buffers with a selected
language.

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
Guilherme TavaresandKirill Bulatov authored and GitHub committed 2026-07-08 12:29:04 +00:00
1 parent eb9b2b8341
commit 1abef8fadf
11 files changed
+129 -22

No files matched your search

+4 -1
View File
@@ -2114,6 +2114,9 @@ impl MultiBuffer {
self.title.as_deref()
}
/// The title used for buffers not backed by a file and with no title of their own.
pub const DEFAULT_TITLE: &str = "untitled";
pub fn title<'a>(&'a self, cx: &'a App) -> Cow<'a, str> {
if let Some(title) = self.title.as_ref() {
return title.into();
@@ -2131,7 +2134,7 @@ impl MultiBuffer {
}
};
"untitled".into()
Self::DEFAULT_TITLE.into()
}
fn buffer_content_title(&self, buffer: &Buffer) -> Option<Cow<'_, str>> {