Merge pull request #135 from lj3954/improved_navigation

feat: Allow navigation with 'h' and 'l' keys
This commit is contained in:
Chris Titus 2024-08-08 17:52:54 -05:00 committed by GitHub
commit a7208e8662
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -356,7 +356,15 @@ impl CustomList {
self.toggle_preview_window(state); self.toggle_preview_window(state);
None None
} }
KeyCode::Enter if self.preview_window_state.is_none() => self.handle_enter(),
KeyCode::Enter | KeyCode::Right | KeyCode::Char('l') => {
if self.preview_window_state.is_none() {
self.handle_enter()
} else {
None
}
}
KeyCode::Left | KeyCode::Char('h') if !self.at_root() => self.enter_parent_directory(),
_ => None, _ => None,
} }
} }
@ -452,6 +460,12 @@ impl CustomList {
None None
} }
fn enter_parent_directory(&mut self) -> Option<Command> {
self.visit_stack.pop();
self.list_state.select(Some(0));
None
}
/// Handles the <Enter> key. This key can do 3 things: /// Handles the <Enter> key. This key can do 3 things:
/// - Run a command, if it is the currently selected item, /// - Run a command, if it is the currently selected item,
/// - Go up a directory /// - Go up a directory
@ -469,9 +483,7 @@ impl CustomList {
.unwrap(); .unwrap();
if !self.at_root() && selected_index == 0 { if !self.at_root() && selected_index == 0 {
self.visit_stack.pop(); return self.enter_parent_directory();
self.list_state.select(Some(0));
return None;
} }
let mut actual_index = selected_index; let mut actual_index = selected_index;