working properly well to distinguish enter in the edit mode now

This commit is contained in:
filipriec
2025-04-18 00:15:34 +02:00
parent f22dd7749f
commit 4db78ecf1b
2 changed files with 72 additions and 37 deletions

View File

@@ -60,16 +60,17 @@ enter_highlight_mode_linewise = ["ctrl+v"]
# BIG CHANGES NOW EXIT HANDLES EITHER IF THOSE
# exit_edit_mode = ["esc","ctrl+e"]
# exit_suggestion_mode = ["esc"]
# select_suggestion = ["enter"]
# next_field = ["enter"]
enter_decider = ["enter"]
prev_field = ["shift+enter"]
exit = ["esc", "ctrl+e"]
delete_char_forward = ["delete"]
delete_char_backward = ["backspace"]
next_field = ["enter"]
prev_field = ["shift+enter"]
move_left = ["left"]
move_right = ["right"]
suggestion_down = ["ctrl+n", "tab"]
suggestion_up = ["ctrl+p", "shift+tab"]
select_suggestion = ["enter"]
[keybindings.command]
exit_command_mode = ["ctrl+g", "esc"]

View File

@@ -6,10 +6,10 @@ use crate::state::pages::{
canvas_state::CanvasState,
};
use crate::state::pages::form::FormState;
use crate::state::pages::add_table::AddTableState; // Added
use crate::state::pages::add_table::AddTableState;
use crate::modes::handlers::event::EventOutcome;
use crate::functions::modes::edit::{auth_e, form_e};
use crate::functions::modes::edit::add_table_e; // Added
use crate::functions::modes::edit::add_table_e;
use crate::state::app::state::AppState;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
@@ -25,7 +25,7 @@ pub async fn handle_edit_event(
form_state: &mut FormState,
login_state: &mut LoginState,
register_state: &mut RegisterState,
add_table_state: &mut AddTableState, // Added
add_table_state: &mut AddTableState,
ideal_cursor_column: &mut usize,
current_position: &mut u64,
total_count: u64,
@@ -38,9 +38,6 @@ pub async fn handle_edit_event(
key.code,
key.modifiers,
) {
// This mode change should likely be handled in event.rs
// Returning a message here might prevent the mode switch.
// Consider if this check is necessary here.
return Ok(EditEventOutcome::Message(
"Command mode entry handled globally.".to_string(),
));
@@ -62,7 +59,6 @@ pub async fn handle_edit_event(
)
.await?
} else if app_state.ui.show_register {
// Keeping this block as requested
auth_e::execute_common_action(
action,
register_state,
@@ -70,14 +66,13 @@ pub async fn handle_edit_event(
current_position,
total_count,
)
.await? // Results in String on success
.await?
} else if app_state.ui.show_add_table {
// Placeholder - common actions for AddTable might be different
format!(
"Action '{}' not fully implemented for Add Table view here.",
action
)
} else { // Assuming FormState otherwise
} else {
let outcome = form_e::execute_common_action(
action,
form_state,
@@ -103,11 +98,65 @@ pub async fn handle_edit_event(
if let Some(action) =
config.get_edit_action_for_key(key.code, key.modifiers)
.as_deref() {
// Handle enter_decider first
if action == "enter_decider" {
let effective_action = if app_state.ui.show_register
&& register_state.in_suggestion_mode
&& register_state.current_field() == 4 {
"select_suggestion"
} else {
"next_field"
};
let msg = if app_state.ui.show_login {
auth_e::execute_edit_action(
effective_action,
key,
login_state,
ideal_cursor_column,
grpc_client,
current_position,
total_count,
)
.await?
} else if app_state.ui.show_add_table {
add_table_e::execute_edit_action(
effective_action,
key,
add_table_state,
ideal_cursor_column,
)
.await?
} else if app_state.ui.show_register {
auth_e::execute_edit_action(
effective_action,
key,
register_state,
ideal_cursor_column,
grpc_client,
current_position,
total_count,
)
.await?
} else {
form_e::execute_edit_action(
effective_action,
key,
form_state,
ideal_cursor_column,
grpc_client,
current_position,
total_count,
)
.await?
};
return Ok(EditEventOutcome::Message(msg));
}
if action == "exit" {
// Handle exiting suggestion mode in Register view first
if app_state.ui.show_register && register_state.in_suggestion_mode {
let msg = auth_e::execute_edit_action(
"exit_suggestion_mode", // Specific action for suggestion exit
"exit_suggestion_mode",
key,
register_state,
ideal_cursor_column,
@@ -118,14 +167,12 @@ pub async fn handle_edit_event(
.await?;
return Ok(EditEventOutcome::Message(msg));
} else {
// Signal exit from Edit mode
return Ok(EditEventOutcome::ExitEditMode);
}
}
// Special handling for role field suggestions (Register view only)
if app_state.ui.show_register && register_state.current_field() == 4 {
// Check if Tab was pressed to *enter* suggestion mode
if !register_state.in_suggestion_mode
&& key.code == KeyCode::Tab
&& key.modifiers == KeyModifiers::NONE
@@ -133,7 +180,7 @@ pub async fn handle_edit_event(
register_state.update_role_suggestions();
if !register_state.role_suggestions.is_empty() {
register_state.in_suggestion_mode = true;
register_state.selected_suggestion_index = Some(0); // Select first suggestion
register_state.selected_suggestion_index = Some(0);
return Ok(EditEventOutcome::Message(
"Suggestions shown".to_string(),
));
@@ -143,17 +190,14 @@ pub async fn handle_edit_event(
));
}
}
// Handle suggestion navigation/selection if already in suggestion mode
if register_state.in_suggestion_mode
&& matches!(
action,
"suggestion_down"
| "suggestion_up"
| "select_suggestion"
"suggestion_down" | "suggestion_up"
)
{
let msg = auth_e::execute_edit_action(
action, // Pass the specific suggestion action
action,
key,
register_state,
ideal_cursor_column,
@@ -184,7 +228,6 @@ pub async fn handle_edit_event(
key,
add_table_state,
ideal_cursor_column,
// Pass other necessary params if add_table_e needs them
)
.await?
} else if app_state.ui.show_register {
@@ -199,7 +242,6 @@ pub async fn handle_edit_event(
)
.await?
} else {
// Assuming FormState otherwise
form_e::execute_edit_action(
action,
key,
@@ -216,18 +258,16 @@ pub async fn handle_edit_event(
// --- Character insertion ---
if let KeyCode::Char(c) = key.code {
// Exit suggestion mode in Register view if a character is typed
if app_state.ui.show_register && register_state.in_suggestion_mode {
register_state.in_suggestion_mode = false;
register_state.show_role_suggestions = false;
register_state.selected_suggestion_index = None;
}
// Execute insert_char action based on the current view
let msg = if app_state.ui.show_login {
auth_e::execute_edit_action(
"insert_char",
key, // Pass the key event containing the char
key,
login_state,
ideal_cursor_column,
grpc_client,
@@ -255,7 +295,6 @@ pub async fn handle_edit_event(
)
.await?
} else {
// Assuming FormState otherwise
form_e::execute_edit_action(
"insert_char",
key,
@@ -267,7 +306,7 @@ pub async fn handle_edit_event(
)
.await?
};
// Update role suggestions after insertion if needed (Register view)
if app_state.ui.show_register && register_state.current_field() == 4 {
register_state.update_role_suggestions();
}
@@ -277,7 +316,6 @@ pub async fn handle_edit_event(
// --- Handle Backspace/Delete ---
if matches!(key.code, KeyCode::Backspace | KeyCode::Delete) {
// Exit suggestion mode in Register view
if app_state.ui.show_register && register_state.in_suggestion_mode {
register_state.in_suggestion_mode = false;
register_state.show_role_suggestions = false;
@@ -290,7 +328,6 @@ pub async fn handle_edit_event(
"delete_char_forward"
};
// Execute delete action based on the current view
let result_msg: String = if app_state.ui.show_login {
auth_e::execute_edit_action(
action_str,
@@ -322,8 +359,7 @@ pub async fn handle_edit_event(
)
.await?
} else {
// Assuming FormState otherwise
form_e::execute_edit_action(
form_e::execute_edit_action(
action_str,
key,
form_state,
@@ -333,7 +369,7 @@ pub async fn handle_edit_event(
total_count
).await?
};
// Update role suggestions after deletion if needed (Register view)
if app_state.ui.show_register && register_state.current_field() == 4 {
register_state.update_role_suggestions();
}
@@ -341,7 +377,5 @@ pub async fn handle_edit_event(
return Ok(EditEventOutcome::Message(result_msg));
}
// Default return if no other handler matched
Ok(EditEventOutcome::Message("".to_string()))
}