use crate::app::{AppState, Action};
use crate::input::InputEvent;
use crate::errors::ComponentError;
use crossterm::event::KeyCode::*;
pub fn handle_conflicts_popup(event: InputEvent, state: &AppState) -> Result<Option<Action>, ComponentError> {
let conflicts: Vec<&crate::git::parsers::status::StatusEntry> = state
.status_entries
.iter()
.filter(|e| e.conflict)
.collect();
let max_idx = conflicts.len().saturating_sub(1);
if let InputEvent::Key(key) = &event {
if key.kind == crossterm::event::KeyEventKind::Press {
return Ok(match key.code {
Esc => Some(Action::HideConflictsPopup),
Up | Char('k') => Some(Action::ConflictsPopupUp),
Down | Char('j') => Some(Action::ConflictsPopupDown),
Enter | Right => {
let idx = state.conflicts_popup_selected.min(max_idx);
let path = conflicts.get(idx).map(|e| e.path.clone());
path.map(Action::SelectConflict)
}
Char('o') => {
let idx = state.conflicts_popup_selected.min(max_idx);
let path = conflicts.get(idx).map(|e| e.path.clone());
path.map(Action::OpenConflictInEditor)
}
_ => None,
});
}
}
Ok(None)
}
pub fn handle_conflicts_guided(event: InputEvent, _state: &AppState) -> Result<Option<Action>, ComponentError> {
if let InputEvent::Key(key) = &event {
if key.kind == crossterm::event::KeyEventKind::Press {
return Ok(match key.code {
Esc => Some(Action::HideConflictsGuided),
Up | Char('k') => Some(Action::ConflictsGuidedUp),
Down | Char('j') => Some(Action::ConflictsGuidedDown),
Enter | Char('o') => Some(Action::OpenGuidedConflictInEditor),
Char('c') => Some(Action::RebaseContinue),
Char('a') => Some(Action::RebaseAbort),
_ => None,
});
}
}
Ok(None)
}