working inputting characters
This commit is contained in:
@@ -84,7 +84,7 @@ pub async fn execute_edit_action<S: CanvasState>(
|
|||||||
return Ok("Error: insert_char called without a char key."
|
return Ok("Error: insert_char called without a char key."
|
||||||
.to_string());
|
.to_string());
|
||||||
}
|
}
|
||||||
Ok("".to_string())
|
Ok("working?".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
"delete_char_backward" => {
|
"delete_char_backward" => {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::modes::common::commands::CommandHandler;
|
|||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
use crate::ui::handlers::rat_state::UiStateHandler;
|
||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
common::{command_mode},
|
common::{command_mode},
|
||||||
@@ -27,7 +28,7 @@ pub struct EventHandler {
|
|||||||
pub edit_mode_cooldown: bool,
|
pub edit_mode_cooldown: bool,
|
||||||
pub ideal_cursor_column: usize,
|
pub ideal_cursor_column: usize,
|
||||||
pub key_sequence_tracker: KeySequenceTracker,
|
pub key_sequence_tracker: KeySequenceTracker,
|
||||||
pub auth_state: AuthState,
|
// pub auth_state: AuthState, // Removed
|
||||||
pub auth_client: AuthClient,
|
pub auth_client: AuthClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ impl EventHandler {
|
|||||||
edit_mode_cooldown: false,
|
edit_mode_cooldown: false,
|
||||||
ideal_cursor_column: 0,
|
ideal_cursor_column: 0,
|
||||||
key_sequence_tracker: KeySequenceTracker::new(800),
|
key_sequence_tracker: KeySequenceTracker::new(800),
|
||||||
auth_state: AuthState::new(),
|
// auth_state: AuthState::new(), // Removed
|
||||||
auth_client: AuthClient::new().await?,
|
auth_client: AuthClient::new().await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -54,6 +55,7 @@ impl EventHandler {
|
|||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
command_handler: &mut CommandHandler,
|
command_handler: &mut CommandHandler,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
|
auth_state: &mut AuthState, // Added
|
||||||
app_state: &mut crate::state::state::AppState,
|
app_state: &mut crate::state::state::AppState,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
@@ -100,10 +102,25 @@ impl EventHandler {
|
|||||||
|
|
||||||
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
||||||
ModeManager::can_enter_edit_mode(current_mode) {
|
ModeManager::can_enter_edit_mode(current_mode) {
|
||||||
let current_input = form_state.get_current_input();
|
let current_input = if app_state.ui.show_login {
|
||||||
if !current_input.is_empty() && form_state.current_cursor_pos < current_input.len() {
|
auth_state.get_current_input()
|
||||||
form_state.current_cursor_pos += 1;
|
} else {
|
||||||
self.ideal_cursor_column = form_state.current_cursor_pos;
|
form_state.get_current_input()
|
||||||
|
};
|
||||||
|
let current_cursor_pos = if app_state.ui.show_login {
|
||||||
|
auth_state.current_cursor_pos()
|
||||||
|
} else {
|
||||||
|
form_state.current_cursor_pos()
|
||||||
|
};
|
||||||
|
|
||||||
|
if !current_input.is_empty() && current_cursor_pos < current_input.len() {
|
||||||
|
if app_state.ui.show_login {
|
||||||
|
auth_state.set_current_cursor_pos(current_cursor_pos + 1);
|
||||||
|
self.ideal_cursor_column = auth_state.current_cursor_pos();
|
||||||
|
} else {
|
||||||
|
form_state.set_current_cursor_pos(current_cursor_pos + 1);
|
||||||
|
self.ideal_cursor_column = form_state.current_cursor_pos();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.is_edit_mode = true;
|
self.is_edit_mode = true;
|
||||||
self.edit_mode_cooldown = true;
|
self.edit_mode_cooldown = true;
|
||||||
@@ -123,7 +140,6 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for core application actions (save, quit, etc.)
|
// Check for core application actions (save, quit, etc.)
|
||||||
// ONLY handle a limited subset of core actions here
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(
|
if let Some(action) = config.get_action_for_key_in_mode(
|
||||||
&config.keybindings.common,
|
&config.keybindings.common,
|
||||||
key_code,
|
key_code,
|
||||||
@@ -134,7 +150,7 @@ impl EventHandler {
|
|||||||
return common_mode::handle_core_action(
|
return common_mode::handle_core_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
&mut self.auth_state,
|
auth_state, // Changed
|
||||||
grpc_client,
|
grpc_client,
|
||||||
&mut self.auth_client,
|
&mut self.auth_client,
|
||||||
terminal,
|
terminal,
|
||||||
@@ -143,17 +159,17 @@ impl EventHandler {
|
|||||||
total_count,
|
total_count,
|
||||||
).await;
|
).await;
|
||||||
},
|
},
|
||||||
_ => {} // For other actions, let the mode-specific handler take care of it
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let read_only mode handle its own actions (including navigation from common bindings)
|
// Let read_only mode handle its own actions
|
||||||
return read_only::handle_read_only_event(
|
return read_only::handle_read_only_event(
|
||||||
&app_state,
|
&app_state,
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
&mut self.auth_state,
|
auth_state, // Changed
|
||||||
&mut self.key_sequence_tracker,
|
&mut self.key_sequence_tracker,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
@@ -167,7 +183,13 @@ impl EventHandler {
|
|||||||
AppMode::Edit => {
|
AppMode::Edit => {
|
||||||
// Check for exiting edit mode
|
// Check for exiting edit mode
|
||||||
if config.is_exit_edit_mode(key_code, modifiers) {
|
if config.is_exit_edit_mode(key_code, modifiers) {
|
||||||
if form_state.has_unsaved_changes {
|
let has_changes = if app_state.ui.show_login {
|
||||||
|
auth_state.has_unsaved_changes()
|
||||||
|
} else {
|
||||||
|
form_state.has_unsaved_changes()
|
||||||
|
};
|
||||||
|
|
||||||
|
if has_changes {
|
||||||
self.command_message = "Unsaved changes! Use :w to save or :q! to discard".to_string();
|
self.command_message = "Unsaved changes! Use :w to save or :q! to discard".to_string();
|
||||||
return Ok((false, self.command_message.clone()));
|
return Ok((false, self.command_message.clone()));
|
||||||
}
|
}
|
||||||
@@ -176,16 +198,31 @@ impl EventHandler {
|
|||||||
self.command_message = "Read-only mode".to_string();
|
self.command_message = "Read-only mode".to_string();
|
||||||
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
||||||
|
|
||||||
let current_input = form_state.get_current_input();
|
let current_input = if app_state.ui.show_login {
|
||||||
if !current_input.is_empty() && form_state.current_cursor_pos >= current_input.len() {
|
auth_state.get_current_input()
|
||||||
form_state.current_cursor_pos = current_input.len() - 1;
|
} else {
|
||||||
self.ideal_cursor_column = form_state.current_cursor_pos;
|
form_state.get_current_input()
|
||||||
|
};
|
||||||
|
let current_cursor_pos = if app_state.ui.show_login {
|
||||||
|
auth_state.current_cursor_pos()
|
||||||
|
} else {
|
||||||
|
form_state.current_cursor_pos()
|
||||||
|
};
|
||||||
|
|
||||||
|
if !current_input.is_empty() && current_cursor_pos >= current_input.len() {
|
||||||
|
let new_pos = current_input.len() - 1;
|
||||||
|
if app_state.ui.show_login {
|
||||||
|
auth_state.set_current_cursor_pos(new_pos);
|
||||||
|
self.ideal_cursor_column = auth_state.current_cursor_pos();
|
||||||
|
} else {
|
||||||
|
form_state.set_current_cursor_pos(new_pos);
|
||||||
|
self.ideal_cursor_column = form_state.current_cursor_pos();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Ok((false, self.command_message.clone()));
|
return Ok((false, self.command_message.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for core application actions (save, quit, etc.)
|
// Check for core application actions (save, quit, etc.)
|
||||||
// ONLY handle a limited subset of core actions here
|
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(
|
if let Some(action) = config.get_action_for_key_in_mode(
|
||||||
&config.keybindings.common,
|
&config.keybindings.common,
|
||||||
key_code,
|
key_code,
|
||||||
@@ -196,7 +233,7 @@ impl EventHandler {
|
|||||||
return common_mode::handle_core_action(
|
return common_mode::handle_core_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
&mut self.auth_state,
|
auth_state, // Changed
|
||||||
grpc_client,
|
grpc_client,
|
||||||
&mut self.auth_client,
|
&mut self.auth_client,
|
||||||
terminal,
|
terminal,
|
||||||
@@ -205,17 +242,17 @@ impl EventHandler {
|
|||||||
total_count,
|
total_count,
|
||||||
).await;
|
).await;
|
||||||
},
|
},
|
||||||
_ => {} // For other actions, let the mode-specific handler take care of it
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let edit mode handle its own actions (including navigation from common bindings)
|
// Let edit mode handle its own actions
|
||||||
let result = edit::handle_edit_event(
|
let result = edit::handle_edit_event(
|
||||||
app_state.ui.show_login,
|
app_state.ui.show_login,
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
&mut self.auth_state,
|
auth_state, // Changed
|
||||||
&mut self.ideal_cursor_column,
|
&mut self.ideal_cursor_column,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
&mut app_state.ui.is_saved,
|
&mut app_state.ui.is_saved,
|
||||||
@@ -224,8 +261,6 @@ impl EventHandler {
|
|||||||
grpc_client,
|
grpc_client,
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.key_sequence_tracker.reset();
|
self.key_sequence_tracker.reset();
|
||||||
return Ok((false, result));
|
return Ok((false, result));
|
||||||
},
|
},
|
||||||
@@ -257,6 +292,5 @@ impl EventHandler {
|
|||||||
self.edit_mode_cooldown = false;
|
self.edit_mode_cooldown = false;
|
||||||
Ok((false, self.command_message.clone()))
|
Ok((false, self.command_message.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ pub struct AuthState {
|
|||||||
pub auth_token: Option<String>,
|
pub auth_token: Option<String>,
|
||||||
pub user_id: Option<String>,
|
pub user_id: Option<String>,
|
||||||
pub role: Option<String>,
|
pub role: Option<String>,
|
||||||
|
pub has_unsaved_changes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuthState {
|
impl AuthState {
|
||||||
@@ -26,6 +27,7 @@ impl AuthState {
|
|||||||
auth_token: None,
|
auth_token: None,
|
||||||
user_id: None,
|
user_id: None,
|
||||||
role: None,
|
role: None,
|
||||||
|
has_unsaved_changes: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,12 +38,16 @@ impl CanvasState for AuthState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn current_cursor_pos(&self) -> usize {
|
fn current_cursor_pos(&self) -> usize {
|
||||||
self.current_cursor_pos
|
let len = match self.current_field {
|
||||||
|
0 => self.username.len(),
|
||||||
|
1 => self.password.len(),
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
self.current_cursor_pos.min(len)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_unsaved_changes(&self) -> bool {
|
fn has_unsaved_changes(&self) -> bool {
|
||||||
// Auth form doesn't need unsaved changes tracking
|
self.has_unsaved_changes
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inputs(&self) -> Vec<&String> {
|
fn inputs(&self) -> Vec<&String> {
|
||||||
@@ -52,7 +58,7 @@ impl CanvasState for AuthState {
|
|||||||
match self.current_field {
|
match self.current_field {
|
||||||
0 => &self.username,
|
0 => &self.username,
|
||||||
1 => &self.password,
|
1 => &self.password,
|
||||||
_ => "", // Return empty string for invalid index instead of panicking
|
_ => "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,20 +74,31 @@ impl CanvasState for AuthState {
|
|||||||
vec!["Username/Email", "Password"]
|
vec!["Username/Email", "Password"]
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Implement the setter methods ---
|
|
||||||
fn set_current_field(&mut self, index: usize) {
|
fn set_current_field(&mut self, index: usize) {
|
||||||
// AuthState only has 2 fields (0 and 1)
|
if index < 2 { // AuthState only has 2 fields
|
||||||
if index < 2 {
|
|
||||||
self.current_field = index;
|
self.current_field = index;
|
||||||
|
// IMPORTANT: Clamp cursor position to the length of the NEW field
|
||||||
|
let len = match self.current_field {
|
||||||
|
0 => self.username.len(),
|
||||||
|
1 => self.password.len(),
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
self.current_cursor_pos = self.current_cursor_pos.min(len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_current_cursor_pos(&mut self, pos: usize) {
|
fn set_current_cursor_pos(&mut self, pos: usize) {
|
||||||
// Optional: Add validation based on current input length if needed
|
let len = match self.current_field {
|
||||||
self.current_cursor_pos = pos;
|
0 => self.username.len(),
|
||||||
|
1 => self.password.len(),
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
// Ensure stored position is always valid
|
||||||
|
self.current_cursor_pos = pos.min(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_has_unsaved_changes(&mut self, _changed: bool) {
|
fn set_has_unsaved_changes(&mut self, changed: bool) {
|
||||||
// Auth form doesn't track unsaved changes, so do nothing
|
// Allow the generic handler to signal changes
|
||||||
|
self.has_unsaved_changes = changed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use crate::config::binds::config::Config;
|
|||||||
use crate::ui::handlers::render::render_ui;
|
use crate::ui::handlers::render::render_ui;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::modes::handlers::event::EventHandler;
|
use crate::modes::handlers::event::EventHandler;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
|
|
||||||
@@ -18,10 +19,10 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let config = Config::load()?;
|
let config = Config::load()?;
|
||||||
let mut terminal = TerminalCore::new()?;
|
let mut terminal = TerminalCore::new()?;
|
||||||
let mut grpc_client = GrpcClient::new().await?;
|
let mut grpc_client = GrpcClient::new().await?;
|
||||||
let auth_client = AuthClient::new().await?;
|
// let auth_client = AuthClient::new().await?; // AuthClient is now inside EventHandler
|
||||||
let mut command_handler = CommandHandler::new();
|
let mut command_handler = CommandHandler::new();
|
||||||
let theme = Theme::from_str(&config.colors.theme);
|
let theme = Theme::from_str(&config.colors.theme);
|
||||||
let mut auth_state = AuthState::default();
|
let mut auth_state = AuthState::default(); // The single source of truth for AuthState
|
||||||
|
|
||||||
// Initialize app_state first
|
// Initialize app_state first
|
||||||
let mut app_state = AppState::new()?;
|
let mut app_state = AppState::new()?;
|
||||||
@@ -32,7 +33,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Initialize FormState with dynamic fields
|
// Initialize FormState with dynamic fields
|
||||||
let mut form_state = FormState::new(column_names);
|
let mut form_state = FormState::new(column_names);
|
||||||
|
|
||||||
// The rest of your UI initialization remains the same
|
// Initialize EventHandler (which now contains AuthClient)
|
||||||
let mut event_handler = EventHandler::new().await?;
|
let mut event_handler = EventHandler::new().await?;
|
||||||
let event_reader = EventReader::new();
|
let event_reader = EventReader::new();
|
||||||
|
|
||||||
@@ -43,13 +44,16 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
loop {
|
loop {
|
||||||
UiService::update_adresar_count(&mut grpc_client, &mut app_state).await?;
|
UiService::update_adresar_count(&mut grpc_client, &mut app_state).await?;
|
||||||
|
|
||||||
|
// Determine edit mode based on EventHandler state
|
||||||
|
let is_edit_mode = event_handler.is_edit_mode;
|
||||||
|
|
||||||
terminal.draw(|f| {
|
terminal.draw(|f| {
|
||||||
render_ui(
|
render_ui(
|
||||||
f,
|
f,
|
||||||
&mut form_state,
|
&mut form_state,
|
||||||
&mut auth_state,
|
&mut auth_state, // Pass the single AuthState instance
|
||||||
&theme,
|
&theme,
|
||||||
event_handler.is_edit_mode,
|
is_edit_mode, // Use determined edit mode
|
||||||
app_state.total_count,
|
app_state.total_count,
|
||||||
app_state.current_position,
|
app_state.current_position,
|
||||||
&app_state.current_dir,
|
&app_state.current_dir,
|
||||||
@@ -71,6 +75,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
&mut grpc_client,
|
&mut grpc_client,
|
||||||
&mut command_handler,
|
&mut command_handler,
|
||||||
&mut form_state,
|
&mut form_state,
|
||||||
|
&mut auth_state, // Pass the single AuthState instance here too
|
||||||
&mut app_state,
|
&mut app_state,
|
||||||
total_count,
|
total_count,
|
||||||
&mut current_position,
|
&mut current_position,
|
||||||
@@ -78,49 +83,74 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
app_state.current_position = current_position;
|
app_state.current_position = current_position;
|
||||||
|
|
||||||
// Handle position changes and update form state
|
// Handle position changes and update form state (Only when form is shown)
|
||||||
if !event_handler.is_edit_mode {
|
if app_state.ui.show_form { // Added check
|
||||||
let current_input = form_state.get_current_input();
|
if !event_handler.is_edit_mode {
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
|
||||||
current_input.len() - 1 // Limit to last character in readonly mode
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
|
||||||
|
|
||||||
// Ensure position never exceeds total_count + 1
|
|
||||||
if app_state.current_position > total_count + 1 {
|
|
||||||
app_state.current_position = total_count + 1;
|
|
||||||
}
|
|
||||||
if app_state.current_position > total_count {
|
|
||||||
// New entry - reset form
|
|
||||||
form_state.reset_to_empty();
|
|
||||||
form_state.current_field = 0;
|
|
||||||
} else if app_state.current_position >= 1 && app_state.current_position <= total_count {
|
|
||||||
// Existing entry - load data
|
|
||||||
let current_position = app_state.current_position;
|
|
||||||
let message = UiService::load_adresar_by_position(
|
|
||||||
&mut grpc_client,
|
|
||||||
&mut app_state,
|
|
||||||
&mut form_state,
|
|
||||||
current_position
|
|
||||||
).await?;
|
|
||||||
|
|
||||||
let current_input = form_state.get_current_input();
|
let current_input = form_state.get_current_input();
|
||||||
let max_cursor_pos = if !event_handler.is_edit_mode && !current_input.is_empty() {
|
let max_cursor_pos = if !current_input.is_empty() {
|
||||||
current_input.len() - 1 // In readonly mode, limit to last character
|
current_input.len() - 1 // Limit to last character in readonly mode
|
||||||
} else {
|
} else {
|
||||||
current_input.len()
|
0
|
||||||
};
|
};
|
||||||
form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||||
event_handler.command_message = message;
|
|
||||||
} else {
|
// Ensure position never exceeds total_count + 1
|
||||||
// Invalid position - reset to first entry
|
if app_state.current_position > total_count + 1 {
|
||||||
app_state.current_position = 1;
|
app_state.current_position = total_count + 1;
|
||||||
|
}
|
||||||
|
if app_state.current_position > total_count {
|
||||||
|
// New entry - reset form
|
||||||
|
form_state.reset_to_empty();
|
||||||
|
form_state.current_field = 0;
|
||||||
|
} else if app_state.current_position >= 1 && app_state.current_position <= total_count {
|
||||||
|
// Existing entry - load data
|
||||||
|
let current_position_to_load = app_state.current_position; // Use a copy
|
||||||
|
let load_message = UiService::load_adresar_by_position(
|
||||||
|
&mut grpc_client,
|
||||||
|
&mut app_state, // Pass app_state mutably if needed by the service
|
||||||
|
&mut form_state,
|
||||||
|
current_position_to_load
|
||||||
|
).await?;
|
||||||
|
|
||||||
|
let current_input = form_state.get_current_input();
|
||||||
|
let max_cursor_pos = if !event_handler.is_edit_mode && !current_input.is_empty() {
|
||||||
|
current_input.len() - 1 // In readonly mode, limit to last character
|
||||||
|
} else {
|
||||||
|
current_input.len()
|
||||||
|
};
|
||||||
|
form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||||
|
// Don't overwrite message from handle_event if load_message is simple success
|
||||||
|
if !load_message.starts_with("Loaded entry") || message.is_empty() {
|
||||||
|
event_handler.command_message = load_message;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Invalid position (e.g., 0) - reset to first entry or new entry mode
|
||||||
|
app_state.current_position = 1.min(total_count + 1); // Go to 1 or new entry if empty
|
||||||
|
if app_state.current_position > total_count {
|
||||||
|
form_state.reset_to_empty();
|
||||||
|
form_state.current_field = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if app_state.ui.show_login {
|
||||||
|
// Handle cursor updates for AuthState if needed, similar to FormState
|
||||||
|
if !event_handler.is_edit_mode {
|
||||||
|
let current_input = auth_state.get_current_input();
|
||||||
|
let max_cursor_pos = if !current_input.is_empty() {
|
||||||
|
current_input.len() - 1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
auth_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Only update command message if handle_event provided one
|
||||||
|
if !message.is_empty() {
|
||||||
|
event_handler.command_message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_handler.command_message = message;
|
|
||||||
if should_exit {
|
if should_exit {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user