From 026241cf72df9a684ec889a146bead9266dba374 Mon Sep 17 00:00:00 2001 From: gavynriebau Date: Sun, 5 Jun 2022 10:27:41 +0800 Subject: Fix panic on close last buffer (#2367) (#2658) * Fix panic on close last buffer (#2367) In certain circumstances it was possible to cause a panic when closing buffers due to some mishandling of view document history. A change has been made to delete removed documents from the history of accessed documents for each view. The ensures we don't attempt to jump to a deleted document by mistake. * Move remove document code into View function 'remove_document' * Replace 'view.jumps.remove' call with 'view.remove_document' call--- helix-view/src/view.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'helix-view/src/view.rs') diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 091d1f2e..a496fe33 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -316,6 +316,11 @@ impl View { )) } + pub fn remove_document(&mut self, doc_id: &DocumentId) { + self.jumps.remove(doc_id); + self.docs_access_history.retain(|doc| doc != doc_id); + } + // pub fn traverse(&self, text: RopeSlice, start: usize, end: usize, fun: F) // where // F: Fn(usize, usize), -- cgit v1.2.3-70-g09d2