Skip to content

Commit

Permalink
feat(oma-console): support navigating with Home/End keys
Browse files Browse the repository at this point in the history
This adds support for navigating to the last page with End key and to
the first page with Home key.
  • Loading branch information
xtexx committed Jan 23, 2025
1 parent 12ac865 commit d390873
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions oma-console/src/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,15 @@ impl<'a> OmaPager<'a> {
self.tips = self.ui_text.searct_tips_with_query(&query);
continue;
}
self.vertical_scroll = 0;
self.vertical_scroll_state =
self.vertical_scroll_state.position(self.vertical_scroll);
self.goto_begin();
}
KeyCode::Char('G') => {
if self.mode == TuiMode::SearchInputText {
query.push('G');
self.tips = self.ui_text.searct_tips_with_query(&query);
continue;
}
self.vertical_scroll =
self.inner_len.saturating_sub(self.area_height.into());
self.vertical_scroll_state =
self.vertical_scroll_state.position(self.vertical_scroll);
self.goto_end();
}
KeyCode::Enter => {
if self.mode != TuiMode::SearchInputText {
Expand Down Expand Up @@ -457,6 +452,12 @@ impl<'a> OmaPager<'a> {
KeyCode::PageDown => {
self.page_down();
}
KeyCode::End => {
self.goto_end();
}
KeyCode::Home => {
self.goto_begin();
}
_ => {}
}
}
Expand All @@ -473,7 +474,7 @@ impl<'a> OmaPager<'a> {
let pos = self
.vertical_scroll
.saturating_add(self.area_height as usize);
if pos <= self.inner_len {
if pos < self.inner_len {
self.vertical_scroll = pos;
} else {
return;
Expand All @@ -488,6 +489,16 @@ impl<'a> OmaPager<'a> {
self.vertical_scroll_state = self.vertical_scroll_state.position(self.vertical_scroll);
}

fn goto_end(&mut self) {
self.vertical_scroll = self.inner_len.saturating_sub(self.area_height.into());
self.vertical_scroll_state = self.vertical_scroll_state.position(self.vertical_scroll);
}

fn goto_begin(&mut self) {
self.vertical_scroll = 0;
self.vertical_scroll_state = self.vertical_scroll_state.position(0);
}

fn right(&mut self) {
let width = self.writer.get_length();

Expand Down

0 comments on commit d390873

Please sign in to comment.