working exactly as i want, now making the login up and down to work properly well

This commit is contained in:
filipriec
2025-03-30 15:03:12 +02:00
parent 6e04c1f267
commit b5a5ebd7c0
3 changed files with 104 additions and 32 deletions

View File

@@ -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<String, Box<dyn std::error::Error>> {
// 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<String, Box<dyn std::error::Error>> {
// 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())
}