From d3d55440494c17545212b9371a617e0b75b57889 Mon Sep 17 00:00:00 2001 From: Emil Hammarstrom Date: Wed, 13 Aug 2025 09:07:50 +0200 Subject: [PATCH] Handle cases where Shift+Tab does not issue a BackTab KeyEvent --- src/handler.rs | 95 ++++++++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/src/handler.rs b/src/handler.rs index 057354b..dd1d4db 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -127,6 +127,55 @@ async fn pair(app: &mut App, sender: UnboundedSender) { } } +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; + app.new_devices_state.select(None); + } + _ => {} + } +} + +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; + } + app.reset_devices_state(); + } + } + FocusedBlock::PairedDevices => { + app.focused_block = FocusedBlock::Adapter; + app.paired_devices_state.select(None); + } + FocusedBlock::NewDevices => { + app.focused_block = FocusedBlock::PairedDevices; + app.new_devices_state.select(None); + } + _ => {} + } +} + pub async fn handle_key_events( key_event: KeyEvent, app: &mut App, @@ -183,50 +232,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; - app.new_devices_state.select(None); - } - _ => {} + 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; - } - app.reset_devices_state(); - } - } - FocusedBlock::PairedDevices => { - app.focused_block = FocusedBlock::Adapter; - app.paired_devices_state.select(None); - } - FocusedBlock::NewDevices => { - app.focused_block = FocusedBlock::PairedDevices; - app.new_devices_state.select(None); - } - _ => {} - }, + KeyCode::BackTab => backward_tab(app), KeyCode::Char('h') => match app.focused_block { FocusedBlock::Adapter => {