reverting back
This commit is contained in:
@@ -15,68 +15,6 @@ pub struct FormState {
|
||||
pub current_cursor_pos: usize,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ReadOnlyHandler for FormState {
|
||||
async fn handle_read_only_action(
|
||||
&mut self,
|
||||
action: &str,
|
||||
grpc_client: &mut GrpcClient,
|
||||
current_position: &mut u64,
|
||||
total_count: u64,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
match action {
|
||||
"previous_entry" => {
|
||||
let new_position = current_position.saturating_sub(1);
|
||||
if new_position >= 1 {
|
||||
*current_position = new_position;
|
||||
let response = grpc_client.get_adresar_by_position(*current_position).await?;
|
||||
self.update_from_response(response);
|
||||
Ok(format!("Loaded entry {}", *current_position))
|
||||
} else {
|
||||
Ok("Already at first entry".into())
|
||||
}
|
||||
},
|
||||
"next_entry" => {
|
||||
if *current_position < total_count {
|
||||
*current_position += 1;
|
||||
let response = grpc_client.get_adresar_by_position(*current_position).await?;
|
||||
self.update_from_response(response);
|
||||
Ok(format!("Loaded entry {}", *current_position))
|
||||
} else {
|
||||
self.reset_to_empty();
|
||||
Ok("New entry mode".into())
|
||||
}
|
||||
},
|
||||
"move_down" => {
|
||||
self.current_field = (self.current_field + 1) % self.fields.len();
|
||||
let current_input = self.get_current_input();
|
||||
let max_pos = current_input.len().saturating_sub(1);
|
||||
self.current_cursor_pos = self.current_cursor_pos.min(max_pos);
|
||||
Ok("".into())
|
||||
},
|
||||
"move_up" => {
|
||||
if self.current_field == 0 {
|
||||
self.current_field = self.fields.len() - 1;
|
||||
} else {
|
||||
self.current_field = self.current_field.saturating_sub(1);
|
||||
}
|
||||
let current_input = self.get_current_input();
|
||||
let max_pos = current_input.len().saturating_sub(1);
|
||||
self.current_cursor_pos = self.current_cursor_pos.min(max_pos);
|
||||
Ok("".into())
|
||||
},
|
||||
_ => Ok(format!("Unknown action: {}", action))
|
||||
}
|
||||
}
|
||||
|
||||
fn adjust_cursor_position(&mut self, ideal_column: &mut usize) {
|
||||
let current_input = self.get_current_input();
|
||||
let max_pos = current_input.len().saturating_sub(1);
|
||||
self.current_cursor_pos = (*ideal_column).min(max_pos);
|
||||
*ideal_column = self.current_cursor_pos;
|
||||
}
|
||||
}
|
||||
|
||||
impl FormState {
|
||||
/// Create a new FormState with dynamic fields.
|
||||
pub fn new(fields: Vec<String>) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user