diff --git a/src/handler.rs b/src/handler.rs index d7af3f1..ab00ef8 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -12,6 +12,50 @@ use tokio::sync::mpsc::UnboundedSender; use tui_input::backend::crossterm::EventHandler; +fn forward_tab(app: &mut App) { + match app.focused_block { + FocusedBlock::Adapter => { + app.focused_block = FocusedBlock::PairedDevices; + app.reset_devices_state(); + } + FocusedBlock::PairedDevices => { + if let Some(selected_controller) = app.controller_state.selected() { + let controller = &app.controllers[selected_controller]; + if controller.new_devices.is_empty() { + app.focused_block = FocusedBlock::Adapter; + } else { + app.focused_block = FocusedBlock::NewDevices; + } + } + } + FocusedBlock::NewDevices => app.focused_block = FocusedBlock::Adapter, + _ => {} + } +} + +fn backward_tab(app: &mut App) { + match app.focused_block { + FocusedBlock::Adapter => { + if let Some(selected_controller) = app.controller_state.selected() { + let controller = &app.controllers[selected_controller]; + if controller.new_devices.is_empty() { + app.focused_block = FocusedBlock::PairedDevices; + } else { + app.focused_block = FocusedBlock::NewDevices; + } + } + } + FocusedBlock::PairedDevices => { + app.focused_block = FocusedBlock::Adapter; + } + FocusedBlock::NewDevices => { + app.focused_block = FocusedBlock::PairedDevices; + app.reset_devices_state(); + } + _ => {} + } +} + pub async fn handle_key_events( key_event: KeyEvent, app: &mut App, @@ -80,45 +124,12 @@ pub async fn handle_key_events( } // Switch focus - KeyCode::Tab => match app.focused_block { - FocusedBlock::Adapter => { - app.focused_block = FocusedBlock::PairedDevices; - app.reset_devices_state(); - } - FocusedBlock::PairedDevices => { - if let Some(selected_controller) = app.controller_state.selected() { - let controller = &app.controllers[selected_controller]; - if controller.new_devices.is_empty() { - app.focused_block = FocusedBlock::Adapter; - } else { - app.focused_block = FocusedBlock::NewDevices; - } - } - } - FocusedBlock::NewDevices => app.focused_block = FocusedBlock::Adapter, - _ => {} + KeyCode::Tab => match key_event.modifiers { + KeyModifiers::SHIFT => backward_tab(app), + _ => forward_tab(app), }, - KeyCode::BackTab => match app.focused_block { - FocusedBlock::Adapter => { - if let Some(selected_controller) = app.controller_state.selected() { - let controller = &app.controllers[selected_controller]; - if controller.new_devices.is_empty() { - app.focused_block = FocusedBlock::PairedDevices; - } else { - app.focused_block = FocusedBlock::NewDevices; - } - } - } - FocusedBlock::PairedDevices => { - app.focused_block = FocusedBlock::Adapter; - } - FocusedBlock::NewDevices => { - app.focused_block = FocusedBlock::PairedDevices; - app.reset_devices_state(); - } - _ => {} - }, + KeyCode::BackTab => backward_tab(app), KeyCode::Char('h') => match app.focused_block { FocusedBlock::Adapter => {