diff --git a/client/src/modes/canvas/read_only.rs b/client/src/modes/canvas/read_only.rs index 71b2663..eeb40f1 100644 --- a/client/src/modes/canvas/read_only.rs +++ b/client/src/modes/canvas/read_only.rs @@ -52,7 +52,8 @@ pub async fn handle_read_only_event( // Try to match the current sequence against Read-Only mode bindings if let Some(action) = config.matches_key_sequence_generalized(&sequence) { - let result = if (action == "previous_entry" || action == "next_entry") && app_state.ui.show_form { + let result = if (action == "previous_entry" || action == "next_entry" || + action == "move_up" || action == "move_down") && app_state.ui.show_form { crate::tui::functions::form::handle_action( action, form_state, @@ -61,27 +62,6 @@ pub async fn handle_read_only_event( total_count, ideal_cursor_column, ).await? - } else if action == "move_up" && app_state.ui.show_form { - crate::tui::functions::form::handle_move_up( - form_state, - ideal_cursor_column, - ).await? - } else if action == "move_down" && app_state.ui.show_form { - crate::tui::functions::form::handle_move_down( - form_state, - ideal_cursor_column, - ).await? - } else if (action == "move_up" || action == "move_down") && app_state.ui.show_login { - // Assuming you have a auth_state in the app_state that can be accessed - if action == "move_up" { - crate::tui::functions::login::handle_move_up( - &mut app_state.auth_state, - ).await? - } else { - crate::tui::functions::login::handle_move_down( - &mut app_state.auth_state, - ).await? - } } else { execute_action( action, @@ -187,12 +167,12 @@ async fn execute_action( "previous_entry" | "next_entry" => { // This will only be called when no component is active key_sequence_tracker.reset(); - Ok(format!("Navigation only available in form mode")) + Ok(format!("Navigation prev/next only available in form mode")) } "move_up" | "move_down" => { // This will only be called when no component is active key_sequence_tracker.reset(); - Ok(format!("Navigation only available in active component")) + Ok(format!("Navigation up/down only available in form mode")) } "exit_edit_mode" => { key_sequence_tracker.reset(); diff --git a/client/src/tui/functions/form.rs b/client/src/tui/functions/form.rs index 673518d..d181d31 100644 --- a/client/src/tui/functions/form.rs +++ b/client/src/tui/functions/form.rs @@ -75,46 +75,38 @@ pub async fn handle_action( Ok("Already at last entry".into()) } } + "move_up" => { + // Change field first + if form_state.current_field == 0 { + form_state.current_field = form_state.fields.len() - 1; + } else { + form_state.current_field = form_state.current_field.saturating_sub(1); + } + + // Get current input AFTER changing field + let current_input = form_state.get_current_input(); + let max_cursor_pos = if !current_input.is_empty() { + current_input.len() - 1 + } else { + 0 + }; + form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos); + Ok("".to_string()) + } + "move_down" => { + // Change field first + form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(); + + // Get current input AFTER changing field + let current_input = form_state.get_current_input(); + let max_cursor_pos = if !current_input.is_empty() { + current_input.len() - 1 + } else { + 0 + }; + form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos); + Ok("".to_string()) + } _ => Err("Unknown form action".into()) } } - -pub async fn handle_move_up( - form_state: &mut FormState, - ideal_cursor_column: &mut usize, -) -> Result> { - // Change field first - if form_state.current_field == 0 { - form_state.current_field = form_state.fields.len() - 1; - } else { - form_state.current_field = form_state.current_field.saturating_sub(1); - } - - // Get current input AFTER changing field - let current_input = form_state.get_current_input(); - let max_cursor_pos = if !current_input.is_empty() { - current_input.len() - 1 - } else { - 0 - }; - form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos); - Ok("".to_string()) -} - -pub async fn handle_move_down( - form_state: &mut FormState, - ideal_cursor_column: &mut usize, -) -> Result> { - // Change field first - form_state.current_field = (form_state.current_field + 1) % form_state.fields.len(); - - // Get current input AFTER changing field - let current_input = form_state.get_current_input(); - let max_cursor_pos = if !current_input.is_empty() { - current_input.len() - 1 - } else { - 0 - }; - form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos); - Ok("".to_string()) -}