use crate::app::{App, DetailSection, Mode};
use crossterm::event::{KeyCode, KeyEvent};
pub struct LogsTab;
impl LogsTab {
pub fn handle_event(app: &mut App, key: KeyEvent) -> bool {
let code = key.code;
match code {
KeyCode::Up | KeyCode::Char('k') | KeyCode::Char('K') => app.detail_commit_up(),
KeyCode::Down | KeyCode::Char('j') | KeyCode::Char('J') => app.detail_commit_down(),
KeyCode::PageUp => app.detail_commit_page_up(app.get_current_page_size()),
KeyCode::PageDown => app.detail_commit_page_down(app.get_current_page_size()),
KeyCode::Home => app.detail_commit_to_top(),
KeyCode::End => app.detail_commit_to_bottom(),
KeyCode::Char('f') => {
app.search_column_selection = 0;
app.mode = Mode::SearchColumnPicker;
}
KeyCode::Char('G') => {
if app.commit_list.limit > 0 {
let add_amount = if app.get_current_max_commits() > 0 {
app.get_current_max_commits()
} else {
200
};
app.commit_list.limit = app.commit_list.limit.saturating_add(add_amount);
app.resync_detail();
app.status_message = Some("Loading more commits...".to_string());
}
}
KeyCode::Enter => {
app.mode = Mode::Inspect;
if app.is_uncommitted_selected() {
app.detail_focus = DetailSection::Staged;
app.last_staging_focus = DetailSection::Staged;
app.status_list.staging_file_selection = 0;
} else {
app.detail_focus = DetailSection::Staged;
app.last_staging_focus = DetailSection::Staged;
app.status_list.file_selection = 0;
}
app.diff.diff_scroll = 0;
app.refresh_file_diff();
}
KeyCode::Esc | KeyCode::Char('q') | KeyCode::Char('Q') => {
app.in_logs_ui = false;
app.commit_list.search_query = None;
app.mode = Mode::Detail;
}
_ => {}
}
false
}
}