@@ -127,6 +127,55 @@ async fn pair(app: &mut App, sender: UnboundedSender<Event>) {
127127 }
128128}
129129
130+ fn forward_tab ( app : & mut App ) {
131+ match app. focused_block {
132+ FocusedBlock :: Adapter => {
133+ app. focused_block = FocusedBlock :: PairedDevices ;
134+ app. reset_devices_state ( ) ;
135+ }
136+ FocusedBlock :: PairedDevices => {
137+ if let Some ( selected_controller) = app. controller_state . selected ( ) {
138+ let controller = & app. controllers [ selected_controller] ;
139+ if controller. new_devices . is_empty ( ) {
140+ app. focused_block = FocusedBlock :: Adapter ;
141+ } else {
142+ app. focused_block = FocusedBlock :: NewDevices ;
143+ }
144+ }
145+ }
146+ FocusedBlock :: NewDevices => {
147+ app. focused_block = FocusedBlock :: Adapter ;
148+ app. new_devices_state . select ( None ) ;
149+ }
150+ _ => { }
151+ }
152+ }
153+
154+ fn backward_tab ( app : & mut App ) {
155+ match app. focused_block {
156+ FocusedBlock :: Adapter => {
157+ if let Some ( selected_controller) = app. controller_state . selected ( ) {
158+ let controller = & app. controllers [ selected_controller] ;
159+ if controller. new_devices . is_empty ( ) {
160+ app. focused_block = FocusedBlock :: PairedDevices ;
161+ } else {
162+ app. focused_block = FocusedBlock :: NewDevices ;
163+ }
164+ app. reset_devices_state ( ) ;
165+ }
166+ }
167+ FocusedBlock :: PairedDevices => {
168+ app. focused_block = FocusedBlock :: Adapter ;
169+ app. paired_devices_state . select ( None ) ;
170+ }
171+ FocusedBlock :: NewDevices => {
172+ app. focused_block = FocusedBlock :: PairedDevices ;
173+ app. new_devices_state . select ( None ) ;
174+ }
175+ _ => { }
176+ }
177+ }
178+
130179pub async fn handle_key_events (
131180 key_event : KeyEvent ,
132181 app : & mut App ,
@@ -183,50 +232,12 @@ pub async fn handle_key_events(
183232 }
184233
185234 // Switch focus
186- KeyCode :: Tab => match app. focused_block {
187- FocusedBlock :: Adapter => {
188- app. focused_block = FocusedBlock :: PairedDevices ;
189- app. reset_devices_state ( ) ;
190- }
191- FocusedBlock :: PairedDevices => {
192- if let Some ( selected_controller) = app. controller_state . selected ( ) {
193- let controller = & app. controllers [ selected_controller] ;
194- if controller. new_devices . is_empty ( ) {
195- app. focused_block = FocusedBlock :: Adapter ;
196- } else {
197- app. focused_block = FocusedBlock :: NewDevices ;
198- }
199- }
200- }
201- FocusedBlock :: NewDevices => {
202- app. focused_block = FocusedBlock :: Adapter ;
203- app. new_devices_state . select ( None ) ;
204- }
205- _ => { }
235+ KeyCode :: Tab => match key_event. modifiers {
236+ KeyModifiers :: SHIFT => backward_tab ( app) ,
237+ _ => forward_tab ( app) ,
206238 } ,
207239
208- KeyCode :: BackTab => match app. focused_block {
209- FocusedBlock :: Adapter => {
210- if let Some ( selected_controller) = app. controller_state . selected ( ) {
211- let controller = & app. controllers [ selected_controller] ;
212- if controller. new_devices . is_empty ( ) {
213- app. focused_block = FocusedBlock :: PairedDevices ;
214- } else {
215- app. focused_block = FocusedBlock :: NewDevices ;
216- }
217- app. reset_devices_state ( ) ;
218- }
219- }
220- FocusedBlock :: PairedDevices => {
221- app. focused_block = FocusedBlock :: Adapter ;
222- app. paired_devices_state . select ( None ) ;
223- }
224- FocusedBlock :: NewDevices => {
225- app. focused_block = FocusedBlock :: PairedDevices ;
226- app. new_devices_state . select ( None ) ;
227- }
228- _ => { }
229- } ,
240+ KeyCode :: BackTab => backward_tab ( app) ,
230241
231242 KeyCode :: Char ( 'h' ) => match app. focused_block {
232243 FocusedBlock :: Adapter => {
0 commit comments