From 026241cf72df9a684ec889a146bead9266dba374 Mon Sep 17 00:00:00 2001 From: gavynriebau Date: Sun, 5 Jun 2022 10:27:41 +0800 Subject: [PATCH] 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/editor.rs | 5 ++--- helix-view/src/view.rs | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c53fcc7f7..f2fb43018 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -681,7 +681,7 @@ pub fn switch(&mut self, id: DocumentId, action: Action) { // Remove the scratch buffer from any jumplists for (view, _) in self.tree.views_mut() { - view.jumps.remove(&id) + view.remove_document(&id); } } else { let jump = (view.doc, doc.selection(view.id).clone()); @@ -814,8 +814,7 @@ enum Action { .tree .views_mut() .filter_map(|(view, _focus)| { - // remove the document from jump list of all views - view.jumps.remove(&doc_id); + view.remove_document(&doc_id); if view.doc == doc_id { // something was previously open in the view, switch to previous doc diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 091d1f2ee..a496fe330 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -316,6 +316,11 @@ pub fn gutter_coords_at_screen_coords(&self, row: u16, column: u16) -> Option(&self, text: RopeSlice, start: usize, end: usize, fun: F) // where // F: Fn(usize, usize),