editor: Remove closed Document after updating Views

When closing a document we must wait until all views have been updated
first - either replacing their current document or closing the view -
before we remove the document from the `documents` map. The
`Editor::_refresh` helper is called by `Editor::close`. It accesses each
View's Document to sync changes and ensure that the cursor is in view.
When closing multiple Views at once, `Editor::_refresh` will attempt
to access the closing Document while refreshing a to-be-closed View.
This commit is contained in:
Michael Davis 2025-03-30 10:35:35 -04:00
parent fb815e2c6f
commit e148d8b311
No known key found for this signature in database

View file

@ -1816,7 +1816,6 @@ impl Editor {
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);
@ -1857,6 +1856,8 @@ impl Editor {
}
}
let doc = self.documents.remove(&doc_id).unwrap();
// If the document we removed was visible in all views, we will have no more views. We don't
// want to close the editor just for a simple buffer close, so we need to create a new view
// containing either an existing document, or a brand new document.