diff options
| author | Aram Drevekenin <aram@poor.dev> | 2021-04-08 11:36:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-08 11:36:49 +0200 |
| commit | 65c75ebb9593dc2a3b2ae5a82db03dad41bd1b10 (patch) | |
| tree | bfd6caeeddb2b0f3b46baaeb59423414ded8a932 /src/client | |
| parent | fix(tabs): do not crash if closing pane in fullscreen (#259) (diff) | |
| download | sl0ppij-65c75ebb9593dc2a3b2ae5a82db03dad41bd1b10.tar.gz sl0ppij-65c75ebb9593dc2a3b2ae5a82db03dad41bd1b10.tar.xz sl0ppij-65c75ebb9593dc2a3b2ae5a82db03dad41bd1b10.zip | |
feat(controls): add quick navigation (#260)
* feat(input): quick navigation
* feat(ui): quick navigation
* style(fmt): rustfmt
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/boundaries.rs | 4 | ||||
| -rw-r--r-- | src/client/tab.rs | 56 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/client/boundaries.rs b/src/client/boundaries.rs index e498da89..28e01a11 100644 --- a/src/client/boundaries.rs +++ b/src/client/boundaries.rs @@ -21,9 +21,9 @@ pub mod boundary_type { pub mod colors { use ansi_term::Colour::{self, Fixed}; - pub const WHITE: Colour = Fixed(255); pub const GREEN: Colour = Fixed(154); pub const GRAY: Colour = Fixed(238); + pub const ORANGE: Colour = Fixed(166); } pub type BoundaryType = &'static str; // easy way to refer to boundary_type above @@ -768,7 +768,7 @@ impl Boundaries { let color = match color.is_some() { true => match input_mode { InputMode::Normal | InputMode::Locked => Some(colors::GREEN), - _ => Some(colors::WHITE), + _ => Some(colors::ORANGE), }, false => None, }; diff --git a/src/client/tab.rs b/src/client/tab.rs index 82c2639f..3a12656d 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -1809,6 +1809,62 @@ impl Tab { } self.render(); } + pub fn focus_next_pane(&mut self) { + if !self.has_selectable_panes() { + return; + } + if self.fullscreen_is_active { + return; + } + let active_pane_id = self.get_active_pane_id().unwrap(); + let mut panes: Vec<(&PaneId, &Box<dyn Pane>)> = self.get_selectable_panes().collect(); + panes.sort_by(|(_a_id, a_pane), (_b_id, b_pane)| { + if a_pane.y() == b_pane.y() { + a_pane.x().cmp(&b_pane.x()) + } else { + a_pane.y().cmp(&b_pane.y()) + } + }); + let first_pane = panes.get(0).unwrap(); + let active_pane_position = panes + .iter() + .position(|(id, _)| *id == &active_pane_id) // TODO: better + .unwrap(); + if let Some(next_pane) = panes.get(active_pane_position + 1) { + self.active_terminal = Some(*next_pane.0); + } else { + self.active_terminal = Some(*first_pane.0); + } + self.render(); + } + pub fn focus_previous_pane(&mut self) { + if !self.has_selectable_panes() { + return; + } + if self.fullscreen_is_active { + return; + } + let active_pane_id = self.get_active_pane_id().unwrap(); + let mut panes: Vec<(&PaneId, &Box<dyn Pane>)> = self.get_selectable_panes().collect(); + panes.sort_by(|(_a_id, a_pane), (_b_id, b_pane)| { + if a_pane.y() == b_pane.y() { + a_pane.x().cmp(&b_pane.x()) + } else { + a_pane.y().cmp(&b_pane.y()) + } + }); + let last_pane = panes.last().unwrap(); + let active_pane_position = panes + .iter() + .position(|(id, _)| *id == &active_pane_id) // TODO: better + .unwrap(); + if active_pane_position == 0 { + self.active_terminal = Some(*last_pane.0); + } else { + self.active_terminal = Some(*panes.get(active_pane_position - 1).unwrap().0); + } + self.render(); + } pub fn move_focus_left(&mut self) { if !self.has_selectable_panes() { return; |
