From edf522ecaef2314b0f3a4e2ecf1c6a9a2790d9a1 Mon Sep 17 00:00:00 2001 From: Canop Date: Wed, 27 Nov 2019 21:01:12 +0100 Subject: fix crash on doing `:rm` on the last child of current root This was due to the selection index being kept when the previously selected path isn't in the tree anymore. --- CHANGELOG.md | 6 ++++-- Cargo.lock | 2 +- Cargo.toml | 2 +- src/flat_tree.rs | 9 +++++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b22ec62..41b9d5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -### Master + +### v0.10.3 - 2019-11-27 +* fix crash on doing `:rm` on the last child of current root * refactor help page generation using Termimad templates -* clear help background when terminal was resized +* clear help background when terminal was resized between redraws ### v0.10.2 - 2019-11-15 diff --git a/Cargo.lock b/Cargo.lock index 23c9a40..4840020 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "broot" -version = "0.10.2" +version = "0.10.3" dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index d90c242..98c7fe6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "broot" -version = "0.10.2" +version = "0.10.3" authors = ["dystroy "] repository = "https://github.com/Canop/broot" documentation = "https://dystroy.org/broot" diff --git a/src/flat_tree.rs b/src/flat_tree.rs index d3a209c..8118821 100644 --- a/src/flat_tree.rs +++ b/src/flat_tree.rs @@ -163,12 +163,17 @@ impl PartialOrd for TreeLine { impl Tree { pub fn refresh(&mut self, page_height: usize) -> Result<(), errors::TreeBuildError> { - let builder = - TreeBuilder::from(self.root().to_path_buf(), self.options.clone(), page_height)?; + let builder = TreeBuilder::from( + self.root().to_path_buf(), + self.options.clone(), + page_height, + )?; let mut tree = builder.build(&TaskLifetime::unlimited()).unwrap(); // should not fail // we save the old selection to try restore it let selected_path = self.selected_line().path.to_path_buf(); mem::swap(&mut self.lines, &mut tree.lines); + self.selection = 0; // so that there's no error if we can't find the selection after refresh + self.scroll = 0; self.try_select_path(&selected_path); self.make_selection_visible(page_height as i32); Ok(()) -- cgit v1.2.3