diff options
author | Canop <cano.petrole@gmail.com> | 2021-04-25 08:09:00 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2021-04-25 08:09:00 +0200 |
commit | 4a35d3d2bcc1defb3500bf205bb2101fbc8f57cf (patch) | |
tree | d12b99ca2db790437fb704af79c0afc6082c9910 | |
parent | dac0ba53021f7c346fde3a25df498bafba7e5ffd (diff) |
staging area: selection on click
-rw-r--r-- | src/stage/filtered_stage.rs | 8 | ||||
-rw-r--r-- | src/stage/stage_state.rs | 14 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/stage/filtered_stage.rs b/src/stage/filtered_stage.rs index 4294b51..66c1622 100644 --- a/src/stage/filtered_stage.rs +++ b/src/stage/filtered_stage.rs @@ -108,6 +108,14 @@ impl FilteredStage { pub fn has_selection(&self) -> bool { self.selection.is_some() } + pub fn try_select_idx(&mut self, idx: usize) -> bool { + if idx < self.paths_idx.len() { + self.selection = Some(idx); + true + } else { + false + } + } pub fn selected_path<'s>(&self, stage: &'s Stage) -> Option<&'s Path> { self.selection .and_then(|pi| self.paths_idx.get(pi)) diff --git a/src/stage/stage_state.rs b/src/stage/stage_state.rs index 8c3dc0a..a6de958 100644 --- a/src/stage/stage_state.rs +++ b/src/stage/stage_state.rs @@ -196,6 +196,20 @@ impl PanelState for StageState { } } + fn on_click( + &mut self, + _x: u16, + y: u16, + _screen: Screen, + _con: &AppContext, + ) -> Result<CmdResult, ProgramError> { + if y > 0 { + // the list starts on the second row + self.filtered_stage.try_select_idx(y as usize - 1 + self.scroll); + } + Ok(CmdResult::Keep) + } + fn on_pattern( &mut self, pat: InputPattern, |