From dc40a2e15325216b887f2d04b906447e2c3781d6 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Sat, 24 May 2025 15:06:09 -0500 Subject: [PATCH 1/2] Replace a single untitled untouched document on Open This may be a controversial opinion. It felt weird to open edit, open a file, and then see "FILE + 1". I didn't care about the empty Untitled document, and there was no reason for it to be kept around. After this pull request, if you launch edit and then Open a new document without editing the existing placeholder untitled document or giving it a name, Edit will close that document and open the new one. This only applies if there is a single untitled document. If there are other documents open, we won't close any untitled documents. We could conceivably expand this behavior to replace *any* untouched untitled document when you Open a new one. --- src/bin/edit/documents.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bin/edit/documents.rs b/src/bin/edit/documents.rs index a8676c148df..b3e476ae7ed 100644 --- a/src/bin/edit/documents.rs +++ b/src/bin/edit/documents.rs @@ -194,6 +194,17 @@ impl DocumentManager { }; doc.set_path(path); + if self.list.len() == 1 + && let Some(current_doc) = self.list.front() + && current_doc.path.is_none() + && current_doc.file_id.is_none() + && !current_doc.buffer.borrow().is_dirty() + { + // If there is only one document, and it has no filename, and it is not dirty, + // replace it with the new document. + self.list.clear(); + } + self.list.push_front(doc); Ok(self.list.front_mut().unwrap()) } From 0de1c4a7cec4f2c6e016c3f0d4a9669863cbff30 Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Mon, 26 May 2025 21:00:00 -0500 Subject: [PATCH 2/2] Extend the behavior to cover any active document --- src/bin/edit/documents.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/bin/edit/documents.rs b/src/bin/edit/documents.rs index b3e476ae7ed..6c5ac6702cf 100644 --- a/src/bin/edit/documents.rs +++ b/src/bin/edit/documents.rs @@ -194,15 +194,14 @@ impl DocumentManager { }; doc.set_path(path); - if self.list.len() == 1 - && let Some(current_doc) = self.list.front() - && current_doc.path.is_none() - && current_doc.file_id.is_none() - && !current_doc.buffer.borrow().is_dirty() + if let Some(active) = self.active() + && active.path.is_none() + && active.file_id.is_none() + && !active.buffer.borrow().is_dirty() { - // If there is only one document, and it has no filename, and it is not dirty, - // replace it with the new document. - self.list.clear(); + // If the current document is a pristine Untitled document with no + // name and no ID, replace it with the new document. + self.remove_active(); } self.list.push_front(doc);