diff --git a/client/src/modes/canvas/read_only.rs b/client/src/modes/canvas/read_only.rs index 8168f41..71b2663 100644 --- a/client/src/modes/canvas/read_only.rs +++ b/client/src/modes/canvas/read_only.rs @@ -61,6 +61,27 @@ 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, @@ -168,6 +189,11 @@ async fn execute_action( key_sequence_tracker.reset(); Ok(format!("Navigation 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")) + } "exit_edit_mode" => { key_sequence_tracker.reset(); command_message.clear(); @@ -193,38 +219,6 @@ async fn execute_action( } Ok("".to_string()) } - "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()) - } "move_word_next" => { let current_input = form_state.get_current_input(); if !current_input.is_empty() { diff --git a/client/src/tui/functions/form.rs b/client/src/tui/functions/form.rs index 295fbce..673518d 100644 --- a/client/src/tui/functions/form.rs +++ b/client/src/tui/functions/form.rs @@ -78,3 +78,43 @@ pub async fn handle_action( _ => 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()) +} diff --git a/client/src/tui/functions/login.rs b/client/src/tui/functions/login.rs index e69de29..c9e9043 100644 --- a/client/src/tui/functions/login.rs +++ b/client/src/tui/functions/login.rs @@ -0,0 +1,38 @@ +// src/tui/functions/login.rs +use crate::state::pages::auth::AuthState; +use crate::state::canvas_state::CanvasState; + +pub async fn handle_move_up( + auth_state: &mut AuthState, +) -> Result> { + if auth_state.current_field > 0 { + auth_state.current_field -= 1; + } else { + // If at first field (username), cycle to button selection + auth_state.current_field = 0; + auth_state.return_selected = false; + } + + // Reset cursor position for the field + auth_state.current_cursor_pos = auth_state.get_current_input().len(); + + Ok("".to_string()) +} + +pub async fn handle_move_down( + auth_state: &mut AuthState, +) -> Result> { + if auth_state.current_field < 1 { + // Moving down from username to password + auth_state.current_field += 1; + + // Reset cursor position for the new field + auth_state.current_cursor_pos = auth_state.get_current_input().len(); + } else { + // Moving from password field to button selection + auth_state.return_selected = false; + } + + Ok("".to_string()) +} +