working now, able to switch between form_e and auth_e
This commit is contained in:
@@ -2,16 +2,17 @@
|
|||||||
|
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::pages::{auth::AuthState, form::FormState};
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::state::AppState;
|
||||||
use crate::functions::modes::edit::form_e;
|
use crate::functions::modes::edit::{auth_e, form_e};
|
||||||
use crossterm::event::{KeyCode, KeyEvent};
|
use crossterm::event::{KeyCode, KeyEvent};
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
pub async fn handle_edit_event_internal<S: CanvasState + Any>(
|
pub async fn handle_edit_event(
|
||||||
|
is_auth_context: bool,
|
||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
state: &mut S,
|
form_state: &mut FormState,
|
||||||
|
auth_state: &mut AuthState,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
is_saved: &mut bool,
|
is_saved: &mut bool,
|
||||||
@@ -19,61 +20,98 @@ pub async fn handle_edit_event_internal<S: CanvasState + Any>(
|
|||||||
total_count: u64,
|
total_count: u64,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
if let Some(action) = config.get_action_for_key_in_mode(
|
|
||||||
|
// Global command mode check
|
||||||
|
if let Some("enter_command_mode") = config.get_action_for_key_in_mode(
|
||||||
&config.keybindings.global,
|
&config.keybindings.global,
|
||||||
key.code,
|
key.code,
|
||||||
key.modifiers,
|
key.modifiers
|
||||||
) {
|
) {
|
||||||
if action == "enter_command_mode" {
|
|
||||||
*command_message = "Switching to Command Mode...".to_string();
|
*command_message = "Switching to Command Mode...".to_string();
|
||||||
return Ok(command_message.clone());
|
return Ok(command_message.clone());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Common actions (save/revert)
|
||||||
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,
|
||||||
key.modifiers,
|
key.modifiers
|
||||||
) {
|
) {
|
||||||
if action == "save" || action == "revert" {
|
if matches!(action, "save" | "revert") {
|
||||||
return form_e::execute_common_action(
|
return if is_auth_context {
|
||||||
|
auth_e::execute_common_action(
|
||||||
action,
|
action,
|
||||||
state,
|
auth_state, // Concrete AuthState
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
is_saved,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count
|
||||||
)
|
).await
|
||||||
.await;
|
} else {
|
||||||
|
form_e::execute_common_action(
|
||||||
|
action,
|
||||||
|
form_state, // Concrete FormState
|
||||||
|
grpc_client,
|
||||||
|
is_saved,
|
||||||
|
current_position,
|
||||||
|
total_count
|
||||||
|
).await
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Edit-specific actions
|
||||||
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
|
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
|
||||||
return form_e::execute_edit_action(
|
return if is_auth_context {
|
||||||
|
auth_e::execute_edit_action(
|
||||||
action,
|
action,
|
||||||
key,
|
key,
|
||||||
state,
|
auth_state, // Full access to AuthState fields
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
is_saved,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count
|
||||||
)
|
).await
|
||||||
.await;
|
} else {
|
||||||
|
form_e::execute_edit_action(
|
||||||
|
action,
|
||||||
|
key,
|
||||||
|
form_state, // Full access to FormState fields
|
||||||
|
ideal_cursor_column,
|
||||||
|
grpc_client,
|
||||||
|
is_saved,
|
||||||
|
current_position,
|
||||||
|
total_count
|
||||||
|
).await
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if let KeyCode::Char(c) = key.code {
|
// Character insertion
|
||||||
return form_e::execute_edit_action(
|
if let KeyCode::Char(_) = key.code {
|
||||||
|
return if is_auth_context {
|
||||||
|
auth_e::execute_edit_action(
|
||||||
"insert_char",
|
"insert_char",
|
||||||
key,
|
key,
|
||||||
state,
|
auth_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
is_saved,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count
|
||||||
)
|
).await
|
||||||
.await;
|
} else {
|
||||||
|
form_e::execute_edit_action(
|
||||||
|
"insert_char",
|
||||||
|
key,
|
||||||
|
form_state,
|
||||||
|
ideal_cursor_column,
|
||||||
|
grpc_client,
|
||||||
|
is_saved,
|
||||||
|
current_position,
|
||||||
|
total_count
|
||||||
|
).await
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(command_message.clone())
|
Ok(command_message.clone())
|
||||||
|
|||||||
@@ -210,31 +210,21 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let edit mode handle its own actions (including navigation from common bindings)
|
// Let edit mode handle its own actions (including navigation from common bindings)
|
||||||
let result = if app_state.ui.show_login {
|
let result = edit::handle_edit_event(
|
||||||
edit::handle_edit_event_internal(
|
app_state.ui.show_login,
|
||||||
key,
|
|
||||||
config,
|
|
||||||
&mut self.auth_state, // Use auth_state instead of form_state
|
|
||||||
&mut self.ideal_cursor_column,
|
|
||||||
&mut self.command_message,
|
|
||||||
&mut app_state.ui.is_saved,
|
|
||||||
current_position,
|
|
||||||
total_count,
|
|
||||||
grpc_client,
|
|
||||||
).await?
|
|
||||||
} else {
|
|
||||||
edit::handle_edit_event_internal(
|
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
|
&mut self.auth_state,
|
||||||
&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,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
).await?
|
).await?;
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
self.key_sequence_tracker.reset();
|
self.key_sequence_tracker.reset();
|
||||||
return Ok((false, result));
|
return Ok((false, result));
|
||||||
|
|||||||
Reference in New Issue
Block a user