Skip to content

Commit

Permalink
Implement 'go to top/bottom' in TUI
Browse files Browse the repository at this point in the history
Now there are 2 new keybindings in TUI:
- 'g' Go to the top of the note list
- 'G' Go to the bottom of the note list
  • Loading branch information
robert-lag committed Feb 4, 2022
1 parent 0006b10 commit 36ab9bb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/brn_tui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ impl BrnTui {
=> BrnTui::increment_selected_value(tui_data, settings),
KeyCode::Char('k') | KeyCode::Up
=> BrnTui::decrement_selected_value(tui_data, settings),
KeyCode::Char('g')
=> BrnTui::select_first_value(tui_data, settings),
KeyCode::Char('G')
=> BrnTui::select_last_value(tui_data, settings),
KeyCode::Char('l') | KeyCode::Right | KeyCode::Enter
=> BrnTui::open_selected_note(terminal, tui_data, settings),
KeyCode::Char('y')
Expand Down Expand Up @@ -268,6 +272,17 @@ impl BrnTui {
BrnTui::show_note_content_preview(tui_data, settings);
}

fn select_first_value(tui_data: &mut TuiData, settings: &mut Settings) {
tui_data.note_list.select(Some(0));
BrnTui::show_note_content_preview(tui_data, settings);
}

fn select_last_value(tui_data: &mut TuiData, settings: &mut Settings) {
let last_index = tui_data.note_list.get_items().len() - 1;
tui_data.note_list.select(Some(last_index));
BrnTui::show_note_content_preview(tui_data, settings);
}

fn show_note_content_preview(tui_data: &mut TuiData, settings: &mut Settings) {
if let Some(selected_note_name) = &tui_data.note_list.selected_item() {
if let Some(note_id) = Database::get_note_id_where(NoteProperty::NoteName, selected_note_name) {
Expand Down

0 comments on commit 36ab9bb

Please sign in to comment.