Suggest unsaved buffer content text as the default filename (#35707)

Closes #24672

This PR complements a feature added earlier by @JosephTLyons (in
https://github.com/zed-industries/zed/pull/32353) where the text is
considered as the tab title in a new buffer. It piggybacks off that
change and sets the title as the suggested filename in the save dialog
(completely mirroring the same functionality in VSCode):

![2025-08-05 11 50
28](https://github.com/user-attachments/assets/49ad9e4a-5559-44b0-a4b0-ae19890e478e)

Release Notes:

- Text entered in a new untitled buffer is considered as the default
filename when saving
This commit is contained in:
Igal Tabachnik 2025-08-15 18:26:38 +03:00 committed by GitHub
parent 485802b9e5
commit 7993ee9c07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 75 additions and 18 deletions

View file

@ -327,26 +327,35 @@ impl<P: LinuxClient + 'static> Platform for P {
done_rx
}
fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver<Result<Option<PathBuf>>> {
fn prompt_for_new_path(
&self,
directory: &Path,
suggested_name: Option<&str>,
) -> oneshot::Receiver<Result<Option<PathBuf>>> {
let (done_tx, done_rx) = oneshot::channel();
#[cfg(not(any(feature = "wayland", feature = "x11")))]
let _ = (done_tx.send(Ok(None)), directory);
let _ = (done_tx.send(Ok(None)), directory, suggested_name);
#[cfg(any(feature = "wayland", feature = "x11"))]
self.foreground_executor()
.spawn({
let directory = directory.to_owned();
let suggested_name = suggested_name.map(|s| s.to_owned());
async move {
let request = match ashpd::desktop::file_chooser::SaveFileRequest::default()
.modal(true)
.title("Save File")
.current_folder(directory)
.expect("pathbuf should not be nul terminated")
.send()
.await
{
let mut request_builder =
ashpd::desktop::file_chooser::SaveFileRequest::default()
.modal(true)
.title("Save File")
.current_folder(directory)
.expect("pathbuf should not be nul terminated");
if let Some(suggested_name) = suggested_name {
request_builder = request_builder.current_name(suggested_name.as_str());
}
let request = match request_builder.send().await {
Ok(request) => request,
Err(err) => {
let result = match err {