Unnamed repository; edit this file 'description' to name the repository.
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.
Michael Davis 11 months ago
parent fb815e2 · commit e148d8b
-rw-r--r--helix-view/src/editor.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index dfade86b..be221899 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -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.