Avoid removing modified documents in Editor::close_document

This fixes a regression from 6da1a79d80. `:buffer-close` on an
unmodified document would cause later panics since the document should
not have been removed. Instead of eagerly removing the document on the
first line we need to wait until we've checked that it's unmodified.
This commit is contained in:
Michael Davis 2025-03-25 09:03:28 -04:00
parent d43de14807
commit 388a3b78e3
No known key found for this signature in database

View file

@ -1809,13 +1809,14 @@ impl Editor {
}
pub fn close_document(&mut self, doc_id: DocumentId, force: bool) -> Result<(), CloseError> {
let doc = match self.documents.remove(&doc_id) {
let doc = match self.documents.get(&doc_id) {
Some(doc) => doc,
None => return Err(CloseError::DoesNotExist),
};
if !force && doc.is_modified() {
return Err(CloseError::BufferModified(doc.display_name().into_owned()));
}
let doc = self.documents.remove(&doc_id).unwrap();
// This will also disallow any follow-up writes
self.saves.remove(&doc_id);