mirror of
https://github.com/helix-editor/helix.git
synced 2025-03-31 09:27:45 +03:00
Avoid removing modified documents in Editor::close_document
This fixes a regression from 6da1a79d80
. `: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.
This commit is contained in:
parent
d43de14807
commit
388a3b78e3
1 changed files with 2 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue