Unnamed repository; edit this file 'description' to name the repository.
Avoid removing modified documents in Editor::close_document
This fixes a regression from 6da1a79d80d9. `: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.
| -rw-r--r-- | helix-view/src/editor.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 27a985ac..dfade86b 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -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); |