33
44use std:: path:: PathBuf ;
55
6- use anyhow:: { Context , Result , anyhow } ;
6+ use anyhow:: { anyhow , Context , Result } ;
77use crossterm:: event:: { Event , KeyCode , KeyEvent , KeyEventKind , KeyModifiers } ;
8- use fuzzy_matcher:: FuzzyMatcher ;
98use fuzzy_matcher:: skim:: SkimMatcherV2 ;
9+ use fuzzy_matcher:: FuzzyMatcher ;
1010
1111use crate :: config:: ConfigStore ;
1212use crate :: model:: { Config , Host } ;
@@ -211,9 +211,13 @@ impl FormState {
211211
212212 pub fn handle_input ( & mut self , key : KeyEvent , config : & Config ) {
213213 // Check if we're on the bastion field (index 5 in the fields array, or 6 if Add form)
214- let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) { 6 } else { 5 } ;
214+ let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) {
215+ 6
216+ } else {
217+ 5
218+ } ;
215219 let is_bastion_field = self . index == bastion_field_idx;
216-
220+
217221 // Handle bastion dropdown if it's open
218222 if is_bastion_field && self . bastion_dropdown . is_some ( ) {
219223 if let Some ( dropdown) = self . bastion_dropdown . as_mut ( ) {
@@ -288,34 +292,50 @@ impl FormState {
288292 }
289293 }
290294 }
291-
295+
292296 match key. code {
293297 KeyCode :: Tab => {
294- let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) { 6 } else { 5 } ;
298+ let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) {
299+ 6
300+ } else {
301+ 5
302+ } ;
295303 // Close dropdown when leaving bastion field
296304 if self . index == bastion_field_idx {
297305 self . bastion_dropdown = None ;
298306 }
299307 self . next ( ) ;
300308 }
301309 KeyCode :: BackTab => {
302- let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) { 6 } else { 5 } ;
310+ let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) {
311+ 6
312+ } else {
313+ 5
314+ } ;
303315 // Close dropdown when leaving bastion field
304316 if self . index == bastion_field_idx {
305317 self . bastion_dropdown = None ;
306318 }
307319 self . prev ( ) ;
308320 }
309321 KeyCode :: Up => {
310- let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) { 6 } else { 5 } ;
322+ let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) {
323+ 6
324+ } else {
325+ 5
326+ } ;
311327 // Close dropdown when leaving bastion field
312328 if self . index == bastion_field_idx {
313329 self . bastion_dropdown = None ;
314330 }
315331 self . prev ( ) ;
316332 }
317333 KeyCode :: Down => {
318- let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) { 6 } else { 5 } ;
334+ let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) {
335+ 6
336+ } else {
337+ 5
338+ } ;
319339 // Close dropdown when leaving bastion field
320340 if self . index == bastion_field_idx {
321341 self . bastion_dropdown = None ;
@@ -428,7 +448,11 @@ impl FormState {
428448 }
429449
430450 fn open_bastion_dropdown ( & mut self , config : & Config ) {
431- let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) { 6 } else { 5 } ;
451+ let bastion_field_idx = if matches ! ( self . kind, FormKind :: Add ) {
452+ 6
453+ } else {
454+ 5
455+ } ;
432456 let mut dropdown = BastionDropdownState :: new ( config) ;
433457 // Initialize search filter with current field value
434458 if let Some ( f) = self . fields . get ( bastion_field_idx) {
@@ -978,7 +1002,11 @@ impl App {
9781002 fn handle_form ( & mut self , key : KeyEvent ) -> Result < Option < AppAction > > {
9791003 if let Some ( form) = self . form . as_mut ( ) {
9801004 // Check if dropdown is open - if so, handle input there first
981- let bastion_field_idx = if matches ! ( form. kind, FormKind :: Add ) { 6 } else { 5 } ;
1005+ let bastion_field_idx = if matches ! ( form. kind, FormKind :: Add ) {
1006+ 6
1007+ } else {
1008+ 5
1009+ } ;
9821010 let is_bastion_field = form. index == bastion_field_idx;
9831011 if is_bastion_field && form. bastion_dropdown . is_some ( ) {
9841012 // If Enter is pressed with dropdown open, let handle_input handle it
@@ -988,7 +1016,7 @@ impl App {
9881016 return Ok ( None ) ;
9891017 }
9901018 }
991-
1019+
9921020 match key. code {
9931021 KeyCode :: Esc => {
9941022 self . mode = Mode :: Normal ;
@@ -1012,7 +1040,7 @@ impl App {
10121040 }
10131041 }
10141042 }
1015- } ,
1043+ }
10161044 _ => {
10171045 form. handle_input ( key, & self . config ) ;
10181046 }
@@ -1477,7 +1505,9 @@ mod tests {
14771505 let spec = parse_ssh_spec ( "host -o StrictHostKeyChecking=no -v" ) . unwrap ( ) ;
14781506 assert_eq ! ( spec. address, "host" ) ;
14791507 assert ! ( spec. options. contains( & "-o" . to_string( ) ) ) ;
1480- assert ! ( spec. options. contains( & "StrictHostKeyChecking=no" . to_string( ) ) ) ;
1508+ assert ! ( spec
1509+ . options
1510+ . contains( & "StrictHostKeyChecking=no" . to_string( ) ) ) ;
14811511 assert ! ( spec. options. contains( & "-v" . to_string( ) ) ) ;
14821512 assert_eq ! ( spec. remote_command, None ) ;
14831513
0 commit comments