From 955a6cd540ca0483859b98512d7404b5f028b8d4 Mon Sep 17 00:00:00 2001 From: Gavyn Riebau Date: Fri, 3 Jun 2022 17:04:25 +0800 Subject: [PATCH 1/3] 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. --- helix-view/src/editor.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c53fcc7f71c0..1f3d57dc1ecd 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -826,6 +826,9 @@ impl Editor { Some(Action::Close(view.id)) } } else { + // documents also need be removed from the view "document access history" + // so we don't accidentally try to jump back to them after they have been deleted + view.docs_access_history.retain(|doc| doc != &doc_id); None } }) From edd5a38688e37054ca545b76c78b6d692209cc5d Mon Sep 17 00:00:00 2001 From: Gavyn Riebau Date: Fri, 3 Jun 2022 19:15:35 +0800 Subject: [PATCH 2/3] Move remove document code into View function 'remove_document' --- helix-view/src/editor.rs | 6 +----- helix-view/src/view.rs | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 1f3d57dc1ecd..8f51c2ee8ba6 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -814,8 +814,7 @@ impl Editor { .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 @@ -826,9 +825,6 @@ impl Editor { Some(Action::Close(view.id)) } } else { - // documents also need be removed from the view "document access history" - // so we don't accidentally try to jump back to them after they have been deleted - view.docs_access_history.retain(|doc| doc != &doc_id); None } }) diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 091d1f2ee1c8..a496fe3306b7 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), From 7c32e0992dcaa378a42ddb391a11a0d3134a5003 Mon Sep 17 00:00:00 2001 From: Gavyn Riebau Date: Fri, 3 Jun 2022 21:10:29 +0800 Subject: [PATCH 3/3] Replace 'view.jumps.remove' call with 'view.remove_document' call --- helix-view/src/editor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 8f51c2ee8ba6..f2fb43018ff9 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -681,7 +681,7 @@ impl Editor { // 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());