use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use crate::app::{App, InputMode};
pub fn handle_triggers_input(app: &mut App, key: KeyEvent) {
let on_enabled = matches!(&app.input_mode, InputMode::Triggers { current_field, .. } if current_field % 3 == 0);
match key.code {
KeyCode::Enter => {
let _ = app.save_triggers();
}
KeyCode::Esc => {
app.open_settings();
}
KeyCode::Tab if key.modifiers.contains(KeyModifiers::SHIFT) => app.previous_field(),
KeyCode::Tab => app.next_field(),
KeyCode::Up => app.previous_field(),
KeyCode::Down => app.next_field(),
KeyCode::Left | KeyCode::Right | KeyCode::Char(' ') if on_enabled => {
if let InputMode::Triggers { enabled, current_field, .. } = &mut app.input_mode {
let event = *current_field / 3;
enabled[event] = !enabled[event];
}
}
KeyCode::Char(_) | KeyCode::Backspace if on_enabled => {
}
KeyCode::Left => app.cursor_left(),
KeyCode::Right => app.cursor_right(),
KeyCode::Char('+') if key.modifiers.contains(KeyModifiers::CONTROL) => {
app.insert_trigger_variable();
}
KeyCode::Char(c) => app.input_char(c),
KeyCode::Backspace => app.delete_char(),
_ => {}
}
}