eazygit 0.5.1

A fast TUI for Git with staging, conflicts, rebase, and palette-first UX
Documentation
use crate::app::{AppState, Action};
use crate::input::InputEvent;
use crate::errors::ComponentError;
use crossterm::event::KeyCode::*;
use crate::app::state::AmendField;

pub fn handle_commit_mode_with_amend(event: InputEvent, state: &AppState) -> Result<Option<Action>, ComponentError> {
    if let InputEvent::Key(key) = &event {
        if key.kind == crossterm::event::KeyEventKind::Press {
            
            // Handle Tab navigation in commit/amend mode
            if key.code == Tab {
                let next_field = match state.amend_editing_field {
                    None | Some(AmendField::Message) => Some(AmendField::AuthorName),
                    Some(AmendField::AuthorName) => Some(AmendField::AuthorEmail),
                    Some(AmendField::AuthorEmail) => Some(AmendField::Message),
                };
                return Ok(Some(Action::SetAmendEditingField(next_field)));
            }
            
            // Route input to appropriate field based on amend_editing_field
            let editing_field = state.amend_editing_field.unwrap_or(AmendField::Message);
            
            return Ok(match key.code {
                Esc => Some(Action::CancelCommit),
                Enter => Some(Action::CommitSubmit),
                Backspace => {
                    match editing_field {
                        AmendField::Message => Some(Action::CommitInputBackspace),
                        AmendField::AuthorName => {
                            let mut name = state.amend_author_name.clone();
                            name.pop();
                            Some(Action::SetAmendAuthorName(name))
                        }
                        AmendField::AuthorEmail => {
                            let mut email = state.amend_author_email.clone();
                            email.pop();
                            Some(Action::SetAmendAuthorEmail(email))
                        }
                    }
                }
                Char(c) => {
                    match editing_field {
                        AmendField::Message => Some(Action::CommitInputChar(c)),
                        AmendField::AuthorName => {
                            let mut name = state.amend_author_name.clone();
                            name.push(c);
                            Some(Action::SetAmendAuthorName(name))
                        }
                        AmendField::AuthorEmail => {
                            let mut email = state.amend_author_email.clone();
                            email.push(c);
                            Some(Action::SetAmendAuthorEmail(email))
                        }
                    }
                }
                _ => None,
            });
        }
    }
    Ok(None)
}