Skip to content

Commit e148d8b

Browse files
committed
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.
1 parent fb815e2 commit e148d8b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

helix-view/src/editor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,6 @@ impl Editor {
18161816
if !force && doc.is_modified() {
18171817
return Err(CloseError::BufferModified(doc.display_name().into_owned()));
18181818
}
1819-
let doc = self.documents.remove(&doc_id).unwrap();
18201819

18211820
// This will also disallow any follow-up writes
18221821
self.saves.remove(&doc_id);
@@ -1857,6 +1856,8 @@ impl Editor {
18571856
}
18581857
}
18591858

1859+
let doc = self.documents.remove(&doc_id).unwrap();
1860+
18601861
// If the document we removed was visible in all views, we will have no more views. We don't
18611862
// want to close the editor just for a simple buffer close, so we need to create a new view
18621863
// containing either an existing document, or a brand new document.

0 commit comments

Comments
 (0)