diff options
author | Canop <cano.petrole@gmail.com> | 2020-12-13 16:41:35 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-12-13 17:22:07 +0100 |
commit | 2c06c7ca0a580618d932325e15d8d40e7640f24d (patch) | |
tree | 5764d009d564a514a285426be6ce497cc65660c9 /src/browser/browser_state.rs | |
parent | ee4f93f4919be4e716bb9b73476473bbc8bd7159 (diff) |
keep selection visible on unfiltering
The selection was sometimes scrolled away on unfiltering.
Also change some formatting.
Diffstat (limited to 'src/browser/browser_state.rs')
-rw-r--r-- | src/browser/browser_state.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index f1a9b60..218ffd8 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -16,9 +16,7 @@ use { verb::*, }, open, - std::{ - path::{Path, PathBuf}, - }, + std::path::{Path, PathBuf}, termimad::Area, }; @@ -28,7 +26,7 @@ pub struct BrowserState { pub tree: Tree, pub filtered_tree: Option<Tree>, pub pending_pattern: InputPattern, // a pattern (or not) which has not yet be applied - pub total_search_required: bool, // whether the pending pattern should be in total search mode + pub total_search_required: bool, // whether the pending pattern should be in total search mode } impl BrowserState { @@ -253,7 +251,9 @@ impl AppState for BrowserState { Internal::back => { if let Some(filtered_tree) = &self.filtered_tree { let filtered_selection = &filtered_tree.selected_line().path; - self.tree.try_select_path(filtered_selection); + if self.tree.try_select_path(filtered_selection) { + self.tree.make_selection_visible(page_height); + } self.filtered_tree = None; AppStateCmdResult::Keep } else if self.tree.selection > 0 { @@ -539,17 +539,15 @@ impl AppState for BrowserState { warn!("refreshing base tree failed : {:?}", e); } // refresh the filtered tree, if any - Command::from_pattern( - match self.filtered_tree { - Some(ref mut tree) => { - if let Err(e) = tree.refresh(page_height, con) { - warn!("refreshing filtered tree failed : {:?}", e); - } - &tree.options.pattern + Command::from_pattern(match self.filtered_tree { + Some(ref mut tree) => { + if let Err(e) = tree.refresh(page_height, con) { + warn!("refreshing filtered tree failed : {:?}", e); } - None => &self.tree.options.pattern, - }, - ) + &tree.options.pattern + } + None => &self.tree.options.pattern, + }) } fn get_flags(&self) -> Vec<Flag> { |