changeset 6684:f0d6c6754fb3

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.
author Michael Davis <mcarsondavis@gmail.com>
date Sun, 30 Mar 2025 10:35:35 -0400
parents 207a53c56347
children 35f8436107f1
files helix-view/src/editor.rs
diffstat 1 files changed, 2 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/helix-view/src/editor.rs	Sat Mar 29 20:44:55 2025 +0100
+++ b/helix-view/src/editor.rs	Sun Mar 30 10:35:35 2025 -0400
@@ -1816,7 +1816,6 @@
         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 @@
             }
         }
 
+        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.