working inputting characters
This commit is contained in:
@@ -12,6 +12,7 @@ pub struct AuthState {
|
||||
pub auth_token: Option<String>,
|
||||
pub user_id: Option<String>,
|
||||
pub role: Option<String>,
|
||||
pub has_unsaved_changes: bool,
|
||||
}
|
||||
|
||||
impl AuthState {
|
||||
@@ -26,6 +27,7 @@ impl AuthState {
|
||||
auth_token: None,
|
||||
user_id: None,
|
||||
role: None,
|
||||
has_unsaved_changes: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,12 +38,16 @@ impl CanvasState for AuthState {
|
||||
}
|
||||
|
||||
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 {
|
||||
// Auth form doesn't need unsaved changes tracking
|
||||
false
|
||||
self.has_unsaved_changes
|
||||
}
|
||||
|
||||
fn inputs(&self) -> Vec<&String> {
|
||||
@@ -52,7 +58,7 @@ impl CanvasState for AuthState {
|
||||
match self.current_field {
|
||||
0 => &self.username,
|
||||
1 => &self.password,
|
||||
_ => "", // Return empty string for invalid index instead of panicking
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,20 +74,31 @@ impl CanvasState for AuthState {
|
||||
vec!["Username/Email", "Password"]
|
||||
}
|
||||
|
||||
// --- Implement the setter methods ---
|
||||
fn set_current_field(&mut self, index: usize) {
|
||||
// AuthState only has 2 fields (0 and 1)
|
||||
if index < 2 {
|
||||
if index < 2 { // AuthState only has 2 fields
|
||||
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) {
|
||||
// Optional: Add validation based on current input length if needed
|
||||
self.current_cursor_pos = pos;
|
||||
let len = match self.current_field {
|
||||
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) {
|
||||
// Auth form doesn't track unsaved changes, so do nothing
|
||||
fn set_has_unsaved_changes(&mut self, changed: bool) {
|
||||
// Allow the generic handler to signal changes
|
||||
self.has_unsaved_changes = changed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user