diff options
author | Canop <cano.petrole@gmail.com> | 2020-07-27 21:03:58 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-07-27 21:03:58 +0200 |
commit | 1974ecff8e14403a9154bf0459fda849f48fb565 (patch) | |
tree | 346435745fa910abcfb60afba7a948cb4aa0e2eb /src | |
parent | 3a2343a1b6cd16240022edf066f0d5341cd2df41 (diff) |
version 0.19.3
Diffstat (limited to 'src')
-rw-r--r-- | src/app/app.rs | 9 | ||||
-rw-r--r-- | src/browser/browser_state.rs | 4 | ||||
-rw-r--r-- | src/preview/preview_state.rs | 20 | ||||
-rw-r--r-- | src/syntactic/syntactic_view.rs | 7 | ||||
-rw-r--r-- | src/verb/internal.rs | 1 |
5 files changed, 31 insertions, 10 deletions
diff --git a/src/app/app.rs b/src/app/app.rs index b83268e..2e8f0c7 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -90,12 +90,15 @@ impl App { /// return true when the panel has been removed (ie it wasn't the last one) fn close_panel(&mut self, panel_idx: usize, screen: &Screen) -> bool { let active_panel_id = self.panels[self.active_panel_idx].id; + if let Some(preview_id) = self.preview { + if self.panels.has_len(2) && self.panels[panel_idx].id != preview_id { + // we don't want to stay with just the preview + return false; + } + } if let Ok(removed_panel) = self.panels.remove(panel_idx) { if self.preview == Some(removed_panel.id) { self.preview = None; - } else if self.panels.has_len(1) && self.preview.is_some() { - info!("closing because only the preview panel is left"); - return false; } Areas::resize_all(self.panels.as_mut_slice(), screen, self.preview.is_some()) .expect("removing a panel should be easy"); diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index b794d40..eca95ae 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -381,8 +381,8 @@ impl AppState for BrowserState { } Internal::panel_left => { if cc.areas.is_first() { - //if cc.preview.is_some() && cc.areas.nb_pos == 2 { - if cc.preview.is_some() && self.selected_path().is_file() { + if cc.preview.is_some() && cc.areas.nb_pos == 2 { + //if cc.preview.is_some() && self.selected_path().is_file() { AppStateCmdResult::ClosePanel { validate_purpose: false, id: cc.preview, diff --git a/src/preview/preview_state.rs b/src/preview/preview_state.rs index 174e128..8bb7741 100644 --- a/src/preview/preview_state.rs +++ b/src/preview/preview_state.rs @@ -27,6 +27,7 @@ pub struct PreviewState { preview: Preview, pending_pattern: InputPattern, // a pattern (or not) which has not yet be applied filtered_preview: Option<Preview>, + removed_pattern: InputPattern, } impl PreviewState { @@ -44,6 +45,7 @@ impl PreviewState { preview, pending_pattern, filtered_preview: None, + removed_pattern: InputPattern::none(), } } fn mut_preview(&mut self) -> &mut Preview { @@ -72,6 +74,7 @@ impl AppState for PreviewState { if let Some(number) = old_selection { self.preview.try_select_line_number(number); } + self.removed_pattern = filtered_preview.pattern(); } } else { if !self.preview.is_filterable() { @@ -221,9 +224,7 @@ impl AppState for PreviewState { ) -> Result<AppStateCmdResult, ProgramError> { match internal_exec.internal { Internal::back => { - if self.filtered_preview.is_some() { - self.on_pattern(InputPattern::none(), &cc.con) - } else if self.mut_preview().get_selected_line_number().is_some() { + if self.mut_preview().get_selected_line_number().is_some() { self.mut_preview().unselect(); Ok(AppStateCmdResult::Keep) } else { @@ -246,6 +247,19 @@ impl AppState for PreviewState { self.mut_preview().try_scroll(ScrollCommand::Pages(-1)); Ok(AppStateCmdResult::Keep) } + //Internal::restore_pattern => { + // debug!("restore_pattern"); + // self.pending_pattern = self.removed_pattern.take(); + // Ok(AppStateCmdResult::Keep) + //} + Internal::panel_left if self.removed_pattern.is_some() => { + debug!("restoring pattern"); + self.pending_pattern = self.removed_pattern.take(); + Ok(AppStateCmdResult::Keep) + } + Internal::panel_right if self.filtered_preview.is_some() => { + self.on_pattern(InputPattern::none(), &cc.con) + } Internal::select_first => { self.mut_preview().select_first(); Ok(AppStateCmdResult::Keep) diff --git a/src/syntactic/syntactic_view.rs b/src/syntactic/syntactic_view.rs index 3f01dae..2947d6e 100644 --- a/src/syntactic/syntactic_view.rs +++ b/src/syntactic/syntactic_view.rs @@ -88,6 +88,7 @@ impl SyntacticView { total_lines_count: 0, }; if sv.read_lines(dam, con)? { + sv.select_first(); Ok(Some(sv)) } else { Ok(None) @@ -194,8 +195,10 @@ impl SyntacticView { } pub fn select_first(&mut self) { - self.selection_idx = Some(0); - self.scroll = 0; + if self.lines.len() > 0 { + self.selection_idx = Some(0); + self.scroll = 0; + } } pub fn select_last(&mut self) { self.selection_idx = Some(self.lines.len()-1); diff --git a/src/verb/internal.rs b/src/verb/internal.rs index 2c91030..d8a8310 100644 --- a/src/verb/internal.rs +++ b/src/verb/internal.rs @@ -90,6 +90,7 @@ Internals! { start_end_panel: "either open or close an additional panel", quit: "quit Broot", refresh: "refresh tree and clear size cache", + //restore_pattern: "restore a pattern which was just removed", select_first: "select the first file", select_last: "select the last file", sort_by_count: "sort by count", |