on master help sign in
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

commit026241cf72df9a684ec889a146bead9266dba374 authorgavynriebau <gavyn.riebau@gmail.com> dateSun 5 Jun 2022, 10:27 (4 years ago) parent5b4e0a3
2 files changed+7−3
helix-view/src/editor.rs+2−3 helix-view/src/view.rs+5
helix-view/src/editor.rs+2−3
@@ -681,7 +681,7 @@ impl Editor {
681681
682682 // Remove the scratch buffer from any jumplists
683683 for (view, _) in self.tree.views_mut() {
684− view.jumps.remove(&id)
684+ view.remove_document(&id);
685685 }
686686 } else {
687687 let jump = (view.doc, doc.selection(view.id).clone());
@@ -814,8 +814,7 @@ impl Editor {
814814 .tree
815815 .views_mut()
816816 .filter_map(|(view, _focus)| {
817− // remove the document from jump list of all views
818− view.jumps.remove(&doc_id);
817+ view.remove_document(&doc_id);
819818
820819 if view.doc == doc_id {
821820 // something was previously open in the view, switch to previous doc
helix-view/src/view.rs+5
@@ -316,6 +316,11 @@ impl View {
316316 ))
317317 }
318318
319+ pub fn remove_document(&mut self, doc_id: &DocumentId) {
320+ self.jumps.remove(doc_id);
321+ self.docs_access_history.retain(|doc| doc != doc_id);
322+ }
323+
319324 // pub fn traverse<F>(&self, text: RopeSlice, start: usize, end: usize, fun: F)
320325 // where
321326 // F: Fn(usize, usize),