on master help sign in
Fix panic on close last buffer (#2367) (#2658)
026241cgavynriebau
helix-view/src/editor.rs+2−3
@@ -681,7 +681,7 @@ impl Editor {
681
681
682 // Remove the scratch buffer from any jumplists
682 // Remove the scratch buffer from any jumplists
683 for (view, _) in self.tree.views_mut() {
683 for (view, _) in self.tree.views_mut() {
684− view.jumps.remove(&id)
684+ view.remove_document(&id);
685 }
685 }
686 } else {
686 } else {
687 let jump = (view.doc, doc.selection(view.id).clone());
687 let jump = (view.doc, doc.selection(view.id).clone());
@@ -814,8 +814,7 @@ impl Editor {
814 .tree
814 .tree
815 .views_mut()
815 .views_mut()
816 .filter_map(|(view, _focus)| {
816 .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);
819
818
820 if view.doc == doc_id {
819 if view.doc == doc_id {
821 // something was previously open in the view, switch to previous doc
820 // something was previously open in the view, switch to previous doc
helix-view/src/view.rs+5
@@ -316,6 +316,11 @@ impl View {
316 ))
316 ))
317 }
317 }
318
318
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+
319 // pub fn traverse<F>(&self, text: RopeSlice, start: usize, end: usize, fun: F)
324 // pub fn traverse<F>(&self, text: RopeSlice, start: usize, end: usize, fun: F)
320 // where
325 // where
321 // F: Fn(usize, usize),
326 // F: Fn(usize, usize),