add keyboard shortcuts for navigating up and down back
This commit is contained in:
parent
d898e2a07e
commit
61a6a45b6c
2 changed files with 30 additions and 0 deletions
|
@ -43,6 +43,34 @@ fn humanize_timestamp(date: DateTime<Local>) -> String {
|
|||
}
|
||||
|
||||
impl MailTabState {
|
||||
pub fn move_down(&mut self) {
|
||||
if self.message_uids.is_empty() {
|
||||
return;
|
||||
}
|
||||
let len = self.message_uids.len();
|
||||
if let Some(selected) = self.message_list.selected() {
|
||||
if selected + 1 < len {
|
||||
self.message_list.select(Some(selected + 1));
|
||||
}
|
||||
} else {
|
||||
self.message_list.select(Some(0));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_up(&mut self) {
|
||||
if self.message_uids.is_empty() {
|
||||
return;
|
||||
}
|
||||
let len = self.message_uids.len();
|
||||
if let Some(selected) = self.message_list.selected() {
|
||||
if selected >= 1 {
|
||||
self.message_list.select(Some(selected - 1));
|
||||
}
|
||||
} else {
|
||||
self.message_list.select(Some(len - 1));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self, f: &mut FrameType, area: Rect) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
|
|
|
@ -77,6 +77,8 @@ pub async fn run_ui(
|
|||
if let Event::Key(KeyEvent { code, .. }) = event {
|
||||
match code {
|
||||
KeyCode::Char('q') => break,
|
||||
KeyCode::Char('j') => mail_tab.move_down(),
|
||||
KeyCode::Char('k') => mail_tab.move_up(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue