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 | |
parent | ee4f93f4919be4e716bb9b73476473bbc8bd7159 (diff) |
keep selection visible on unfiltering
The selection was sometimes scrolled away on unfiltering.
Also change some formatting.
Diffstat (limited to 'src')
86 files changed, 669 insertions, 674 deletions
diff --git a/src/app/app.rs b/src/app/app.rs index 36e586c..403d622 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -28,7 +28,7 @@ use { const ESCAPE_TO_QUIT: bool = false; -#[cfg(feature="client-server")] +#[cfg(feature = "client-server")] use std::sync::{Arc, Mutex}; /// The GUI @@ -55,7 +55,7 @@ pub struct App { preview: Option<PanelId>, /// the root of the active panel - #[cfg(feature="client-server")] + #[cfg(feature = "client-server")] root: Arc<Mutex<PathBuf>>, /// sender to the sequence channel @@ -96,7 +96,7 @@ impl App { created_panels_count: 1, preview: None, - #[cfg(feature="client-server")] + #[cfg(feature = "client-server")] root: Arc::new(Mutex::new(con.launch_args.root.clone())), tx_seqs, rx_seqs, @@ -105,7 +105,7 @@ impl App { /// return the current index of the panel whith given id fn panel_idx(&self, id: PanelId) -> Option<usize> { - self.panels.iter().position(|panel| panel.id==id) + self.panels.iter().position(|panel| panel.id == id) } fn state(&self) -> &dyn AppState { @@ -140,11 +140,17 @@ impl App { if self.preview == Some(removed_panel.id) { self.preview = None; } - Areas::resize_all(self.panels.as_mut_slice(), self.screen, self.preview.is_some()) - .expect("removing a panel should be easy"); - self.active_panel_idx = self.panels.iter() + Areas::resize_all( + self.panels.as_mut_slice(), + self.screen, + self.preview.is_some(), + ) + .expect("removing a panel should be easy"); + self.active_panel_idx = self + .panels + .iter() .position(|p| p.id == active_panel_id) - .unwrap_or(self.panels.len().get()-1); + .unwrap_or(self.panels.len().get() - 1); true } else { false // there's no other panel to go to @@ -206,7 +212,7 @@ impl App { if len == 3 { if let Some(preview_id) = self.preview { for (idx, panel) in self.panels.iter().enumerate() { - if self.active_panel_idx!=idx && panel.id != preview_id { + if self.active_panel_idx != idx && panel.id != preview_id { return Some(panel.state().selected_path().to_path_buf()); } } @@ -360,7 +366,12 @@ impl App { self.active_panel_idx }; let with_preview = purpose.is_preview() || self.preview.is_some(); - match Areas::create(self.panels.as_mut_slice(), insertion_idx, screen, with_preview) { + match Areas::create( + self.panels.as_mut_slice(), + insertion_idx, + screen, + with_preview, + ) { Ok(areas) => { let panel_id = self.created_panels_count.into(); let mut panel = Panel::new(panel_id, state, areas, con); @@ -532,7 +543,9 @@ impl App { self.screen.clear_bottom_right_char(w, &skin.focused)?; if let Some(raw_sequence) = &con.launch_args.commands { - self.tx_seqs.send(Sequence::new_local(raw_sequence.to_string())).unwrap(); + self.tx_seqs + .send(Sequence::new_local(raw_sequence.to_string())) + .unwrap(); } #[cfg(feature="client-server")] @@ -567,7 +580,11 @@ impl App { } Event::Resize(w, h) => { self.screen.set_terminal_size(w, h, con); - Areas::resize_all(self.panels.as_mut_slice(), self.screen, self.preview.is_some())?; + Areas::resize_all( + self.panels.as_mut_slice(), + self.screen, + self.preview.is_some(), + )?; for panel in &mut self.panels { panel.mut_state().refresh(self.screen, con); } diff --git a/src/app/context.rs b/src/app/context.rs index 0cd8ff9..67e2a2e 100644 --- a/src/app/context.rs +++ b/src/app/context.rs @@ -59,7 +59,7 @@ pub struct AppContext { /// map extensions to icons, icon set chosen based on config /// Send, Sync safely beause once created, everything is immutable - pub icons: Option<Box<dyn IconPlugin + Send + Sync >>, + pub icons: Option<Box<dyn IconPlugin + Send + Sync>>, } impl AppContext { @@ -81,11 +81,15 @@ impl AppContext { .iter() .map(|(k, v)| SpecialPath::new(k.clone(), *v)) .collect(); - let search_modes = config.search_modes.as_ref() + let search_modes = config + .search_modes + .as_ref() .map(|map| map.try_into()) .transpose()? .unwrap_or_default(); - let cols = config.cols_order.as_ref() + let cols = config + .cols_order + .as_ref() .map(Cols::try_from) .transpose()? .unwrap_or(DEFAULT_COLS); diff --git a/src/app/mod.rs b/src/app/mod.rs index 7cc3ea6..cac66f0 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -6,22 +6,22 @@ mod panel; mod panel_id; mod panel_purpose; mod selection; +mod standard_status; mod state; mod state_type; mod status; -mod standard_status; pub use { app::App, - cmd_result::*, cmd_context::CmdContext, + cmd_result::*, context::AppContext, panel::Panel, panel_id::PanelId, panel_purpose::PanelPurpose, selection::{LineNumber, Selection, SelectionType}, + standard_status::StandardStatus, state::*, state_type::AppStateType, status::Status, - standard_status::StandardStatus, }; diff --git a/src/app/panel.rs b/src/app/panel.rs index 8634baa..f9149ae 100644 --- a/src/app/panel.rs +++ b/src/app/panel.rs @@ -70,7 +70,7 @@ impl Panel { preview: Option<PanelId>, con: &AppContext, ) -> Result<AppStateCmdResult, ProgramError> { - let state_idx = self.states.len()-1; + let state_idx = self.states.len() - 1; let cc = CmdContext { cmd, other_path, @@ -82,7 +82,9 @@ impl Panel { }; let result = self.states[state_idx].on_command(w, &cc, screen); let has_previous_state = self.states.len() > 1; - self.status = self.state().get_status(cmd, other_path, has_previous_state, con); + self.status = self + .state() + .get_status(cmd, other_path, has_previous_state, con); debug!("result in panel {:?}: {:?}", &self.id, &result); result } @@ -96,7 +98,9 @@ impl Panel { ) { let cmd = Command::from_raw(self.input.get_content(), false); let has_previous_state = self.states.len() > 1; - self.status = self.state().get_status(&cmd, other_path, has_previous_state, con); + self.status = self + .state() + .get_status(&cmd, other_path, has_previous_state, con); } /// execute all the pending tasks until there's none remaining or @@ -138,7 +142,7 @@ impl Panel { event: Event, con: &AppContext, ) -> Result<Command, ProgramError> { - let sel = self.states[self.states.len()-1].selection(); + let sel = self.states[self.states.len() - 1].selection(); self.input.on_event(w, event, con, sel) } @@ -206,7 +210,8 @@ impl Panel { con: &AppContext, ) -> Result<(), ProgramError> { let state_area = self.areas.state.clone(); - self.mut_state().display(w, screen, state_area, panel_skin, con)?; + self.mut_state() + .display(w, screen, state_area, panel_skin, con)?; if active || !WIDE_STATUS { self.write_status(w, panel_skin, screen)?; } @@ -233,7 +238,14 @@ impl Panel { screen: Screen, ) -> Result<(), ProgramError> { let task = self.state().get_pending_task(); - status_line::write(w, task, &self.status, &self.areas.status, panel_skin, screen) + status_line::write( + w, + task, + &self.status, + &self.areas.status, + panel_skin, + screen, + ) } /// if a panel has a specific purpose (i.e. is here for @@ -250,7 +262,9 @@ impl Panel { return Ok(()); } if let Some(area) = &self.areas.purpose { - let shortcut = con.verb_store.verbs + let shortcut = con + .verb_store + .verbs .iter() .filter(|v| match &v.execution { VerbExecution::Internal(exec) => exec.internal == Internal::start_end_panel, diff --git a/src/app/panel_id.rs b/src/app/panel_id.rs index 2b53875..01d9216 100644 --- a/src/app/panel_id.rs +++ b/src/app/panel_id.rs @@ -1,4 +1,3 @@ - /// The unique identifiant of a panel #[derive(Debug, Clone, Copy, PartialEq)] pub struct PanelId(usize); diff --git a/src/app/selection.rs b/src/app/selection.rs index 4a106f0..7b72a9a 100644 --- a/src/app/selection.rs +++ b/src/app/selection.rs @@ -70,4 +70,3 @@ impl Selection<'_> { } } - diff --git a/src/app/standard_status.rs b/src/app/standard_status.rs index 0d11b5b..46c9918 100644 --- a/src/app/standard_status.rs +++ b/src/app/standard_status.rs @@ -29,19 +29,24 @@ impl StandardStatus { pub fn new(verb_store: &VerbStore) -> Self { let tree_top_focus = "*enter* to go up".to_string(); // enter is hardcoded on focus let tree_dir_focus = "*enter* to focus".to_string(); - let tree_dir_cd = verb_store.key_desc_of_internal_stype(Internal::open_leave, SelectionType::Directory) + let tree_dir_cd = verb_store + .key_desc_of_internal_stype(Internal::open_leave, SelectionType::Directory) .map(|k| format!("*{}* to cd", k)); - let tree_file_open_stay = verb_store.key_desc_of_internal_stype(Internal::open_stay, SelectionType::File) + let tree_file_open_stay = verb_store + .key_desc_of_internal_stype(Internal::open_stay, SelectionType::File) .map(|k| format!("*{}* to open the file", k)); - let tree_file_open_leave = verb_store.key_desc_of_internal_stype(Internal::open_leave, SelectionType::File) + let tree_file_open_leave = verb_store + .key_desc_of_internal_stype(Internal::open_leave, SelectionType::File) .map(|k| format!("*{}* to open and quit", k)); //let tree_file_enter = None; // TODO (for when enter is customized) let tree_unfiltered = "a few letters to search".to_string(); let tree_filtered = "*esc* to clear the filter".to_string(); let preview_unfiltered = "a pattern to filter".to_string(); - let preview_filtered = verb_store.key_desc_of_internal(Internal::panel_right) + let preview_filtered = verb_store + .key_desc_of_internal(Internal::panel_right) .map(|k| format!("*{}* to reveal the text", k)); - let preview_restorable_filter = verb_store.key_desc_of_internal(Internal::panel_left) + let preview_restorable_filter = verb_store + .key_desc_of_internal(Internal::panel_left) .map(|k| format!("*{}* to restore the filter", k)); let not_first_state = "*esc* to go back".to_string(); let help = "*?* for help".to_string(); @@ -91,13 +96,12 @@ impl<'b> StatusParts<'b> { fn to_status(&self) -> Status { let mut md = String::new(); for (i, p) in self.md_parts.iter().enumerate() { - md.push_str( - if i==0 { - "Hit " - } else if i == self.md_parts.len() - 1 { - ", or " - } else { - ", " + md.push_str(if i == 0 { + "Hit " + } else if i == self.md_parts.len() - 1 { + ", or " + } else { + ", " }); md.push_str(p); } diff --git a/src/app/state.rs b/src/app/state.rs index d396c7a..7160d80 100644 --- a/src/app/state.rs +++ b/src/app/state.rs @@ -89,19 +89,19 @@ pub trait AppState { Ok(match internal_exec.internal { Internal::back => AppStateCmdResult::PopState, Internal::copy_path => { - #[cfg(not(feature="clipboard"))] + #[cfg(not(feature = "clipboard"))] { AppStateCmdResult::DisplayError( - "Clipboard feature not enabled at compilation".to_string() + "Clipboard feature not enabled at compilation".to_string(), ) } - #[cfg(feature="clipboard")] + #[cfg(feature = "clipboard")] { let path = self.selected_path().to_string_lossy().to_string(); match terminal_clipboard::set_string(path) { Ok(()) => AppStateCmdResult::Keep, Err(_) => AppStateCmdResult::DisplayError( - "Clipboard error while copying path".to_string() + "Clipboard error while copying path".to_string(), ), } } @@ -161,55 +161,50 @@ pub trait AppState { Internal::preview_text => self.open_preview(Some(PreviewMode::Text), false, cc), Internal::preview_binary => self.open_preview(Some(PreviewMode::Hex), false, cc), Internal::toggle_preview => self.open_preview(None, true, cc), - Internal::sort_by_count => { - self.with_new_options( - screen, &|o| { - if o.sort == Sort::Count { - o.sort = Sort::None; - o.show_counts = false; - } else { - o.sort = Sort::Count; - o.show_counts = true; - } - }, - bang, |