Skip to content

Commit

Permalink
Add 'H' to focus parent without collapsing current node.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJuliusMartinez committed Aug 25, 2021
1 parent acf8ee3 commit ed21d57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl JLess {
// These ignore the input buffer
Key::Left | Key::Char('h') => Some(Action::MoveLeft),
Key::Right | Key::Char('l') => Some(Action::MoveRight),
Key::Char('H') => Some(Action::FocusParent),
Key::Char('i') => Some(Action::ToggleCollapsed),
Key::Char('^') => Some(Action::FocusFirstSibling),
Key::Char('$') => Some(Action::FocusLastSibling),
Expand Down
8 changes: 8 additions & 0 deletions src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub enum Action {
MoveLeft,
MoveRight,

FocusParent,

// The behavior of these is subtle and stateful. These move to the previous/next sibling of the
// focused element. If we are focused on the first/last child, we will move to the parent, but
// we will remember what depth we were at when we first performed this action, and move back
Expand Down Expand Up @@ -99,6 +101,7 @@ impl JsonViewer {
Action::MoveDown(n) => self.move_down(n),
Action::MoveLeft => self.move_left(),
Action::MoveRight => self.move_right(),
Action::FocusParent => self.focus_parent(),
Action::FocusPrevSibling(n) => self.focus_prev_sibling(n),
Action::FocusNextSibling(n) => self.focus_next_sibling(n),
Action::FocusFirstSibling => self.focus_first_sibling(),
Expand Down Expand Up @@ -137,6 +140,7 @@ impl JsonViewer {
Action::MoveDown(_) => true,
Action::MoveLeft => true,
Action::MoveRight => true,
Action::FocusParent => true,
Action::FocusPrevSibling(_) => true,
Action::FocusNextSibling(_) => true,
Action::FocusFirstSibling => true,
Expand Down Expand Up @@ -248,6 +252,10 @@ impl JsonViewer {
return;
}

self.focus_parent();
}

fn focus_parent(&mut self) {
if let OptionIndex::Index(parent) = self.flatjson[self.focused_row].parent {
self.focused_row = parent;
}
Expand Down

0 comments on commit ed21d57

Please sign in to comment.