working properly well to distinguish enter in the edit mode now
This commit is contained in:
@@ -60,16 +60,17 @@ enter_highlight_mode_linewise = ["ctrl+v"]
|
|||||||
# BIG CHANGES NOW EXIT HANDLES EITHER IF THOSE
|
# BIG CHANGES NOW EXIT HANDLES EITHER IF THOSE
|
||||||
# exit_edit_mode = ["esc","ctrl+e"]
|
# exit_edit_mode = ["esc","ctrl+e"]
|
||||||
# exit_suggestion_mode = ["esc"]
|
# exit_suggestion_mode = ["esc"]
|
||||||
|
# select_suggestion = ["enter"]
|
||||||
|
# next_field = ["enter"]
|
||||||
|
enter_decider = ["enter"]
|
||||||
|
prev_field = ["shift+enter"]
|
||||||
exit = ["esc", "ctrl+e"]
|
exit = ["esc", "ctrl+e"]
|
||||||
delete_char_forward = ["delete"]
|
delete_char_forward = ["delete"]
|
||||||
delete_char_backward = ["backspace"]
|
delete_char_backward = ["backspace"]
|
||||||
next_field = ["enter"]
|
|
||||||
prev_field = ["shift+enter"]
|
|
||||||
move_left = ["left"]
|
move_left = ["left"]
|
||||||
move_right = ["right"]
|
move_right = ["right"]
|
||||||
suggestion_down = ["ctrl+n", "tab"]
|
suggestion_down = ["ctrl+n", "tab"]
|
||||||
suggestion_up = ["ctrl+p", "shift+tab"]
|
suggestion_up = ["ctrl+p", "shift+tab"]
|
||||||
select_suggestion = ["enter"]
|
|
||||||
|
|
||||||
[keybindings.command]
|
[keybindings.command]
|
||||||
exit_command_mode = ["ctrl+g", "esc"]
|
exit_command_mode = ["ctrl+g", "esc"]
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ use crate::state::pages::{
|
|||||||
canvas_state::CanvasState,
|
canvas_state::CanvasState,
|
||||||
};
|
};
|
||||||
use crate::state::pages::form::FormState;
|
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::modes::handlers::event::EventOutcome;
|
||||||
use crate::functions::modes::edit::{auth_e, form_e};
|
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 crate::state::app::state::AppState;
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ pub async fn handle_edit_event(
|
|||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
login_state: &mut LoginState,
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
add_table_state: &mut AddTableState, // Added
|
add_table_state: &mut AddTableState,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
@@ -38,9 +38,6 @@ pub async fn handle_edit_event(
|
|||||||
key.code,
|
key.code,
|
||||||
key.modifiers,
|
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(
|
return Ok(EditEventOutcome::Message(
|
||||||
"Command mode entry handled globally.".to_string(),
|
"Command mode entry handled globally.".to_string(),
|
||||||
));
|
));
|
||||||
@@ -62,7 +59,6 @@ pub async fn handle_edit_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
// Keeping this block as requested
|
|
||||||
auth_e::execute_common_action(
|
auth_e::execute_common_action(
|
||||||
action,
|
action,
|
||||||
register_state,
|
register_state,
|
||||||
@@ -70,14 +66,13 @@ pub async fn handle_edit_event(
|
|||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
)
|
)
|
||||||
.await? // Results in String on success
|
.await?
|
||||||
} else if app_state.ui.show_add_table {
|
} else if app_state.ui.show_add_table {
|
||||||
// Placeholder - common actions for AddTable might be different
|
|
||||||
format!(
|
format!(
|
||||||
"Action '{}' not fully implemented for Add Table view here.",
|
"Action '{}' not fully implemented for Add Table view here.",
|
||||||
action
|
action
|
||||||
)
|
)
|
||||||
} else { // Assuming FormState otherwise
|
} else {
|
||||||
let outcome = form_e::execute_common_action(
|
let outcome = form_e::execute_common_action(
|
||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
@@ -103,11 +98,65 @@ pub async fn handle_edit_event(
|
|||||||
if let Some(action) =
|
if let Some(action) =
|
||||||
config.get_edit_action_for_key(key.code, key.modifiers)
|
config.get_edit_action_for_key(key.code, key.modifiers)
|
||||||
.as_deref() {
|
.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" {
|
if action == "exit" {
|
||||||
// Handle exiting suggestion mode in Register view first
|
|
||||||
if app_state.ui.show_register && register_state.in_suggestion_mode {
|
if app_state.ui.show_register && register_state.in_suggestion_mode {
|
||||||
let msg = auth_e::execute_edit_action(
|
let msg = auth_e::execute_edit_action(
|
||||||
"exit_suggestion_mode", // Specific action for suggestion exit
|
"exit_suggestion_mode",
|
||||||
key,
|
key,
|
||||||
register_state,
|
register_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
@@ -118,14 +167,12 @@ pub async fn handle_edit_event(
|
|||||||
.await?;
|
.await?;
|
||||||
return Ok(EditEventOutcome::Message(msg));
|
return Ok(EditEventOutcome::Message(msg));
|
||||||
} else {
|
} else {
|
||||||
// Signal exit from Edit mode
|
|
||||||
return Ok(EditEventOutcome::ExitEditMode);
|
return Ok(EditEventOutcome::ExitEditMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special handling for role field suggestions (Register view only)
|
// Special handling for role field suggestions (Register view only)
|
||||||
if app_state.ui.show_register && register_state.current_field() == 4 {
|
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
|
if !register_state.in_suggestion_mode
|
||||||
&& key.code == KeyCode::Tab
|
&& key.code == KeyCode::Tab
|
||||||
&& key.modifiers == KeyModifiers::NONE
|
&& key.modifiers == KeyModifiers::NONE
|
||||||
@@ -133,7 +180,7 @@ pub async fn handle_edit_event(
|
|||||||
register_state.update_role_suggestions();
|
register_state.update_role_suggestions();
|
||||||
if !register_state.role_suggestions.is_empty() {
|
if !register_state.role_suggestions.is_empty() {
|
||||||
register_state.in_suggestion_mode = true;
|
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(
|
return Ok(EditEventOutcome::Message(
|
||||||
"Suggestions shown".to_string(),
|
"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
|
if register_state.in_suggestion_mode
|
||||||
&& matches!(
|
&& matches!(
|
||||||
action,
|
action,
|
||||||
"suggestion_down"
|
"suggestion_down" | "suggestion_up"
|
||||||
| "suggestion_up"
|
|
||||||
| "select_suggestion"
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
let msg = auth_e::execute_edit_action(
|
let msg = auth_e::execute_edit_action(
|
||||||
action, // Pass the specific suggestion action
|
action,
|
||||||
key,
|
key,
|
||||||
register_state,
|
register_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
@@ -184,7 +228,6 @@ pub async fn handle_edit_event(
|
|||||||
key,
|
key,
|
||||||
add_table_state,
|
add_table_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
// Pass other necessary params if add_table_e needs them
|
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
@@ -199,7 +242,6 @@ pub async fn handle_edit_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
// Assuming FormState otherwise
|
|
||||||
form_e::execute_edit_action(
|
form_e::execute_edit_action(
|
||||||
action,
|
action,
|
||||||
key,
|
key,
|
||||||
@@ -216,18 +258,16 @@ pub async fn handle_edit_event(
|
|||||||
|
|
||||||
// --- Character insertion ---
|
// --- Character insertion ---
|
||||||
if let KeyCode::Char(c) = key.code {
|
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 {
|
if app_state.ui.show_register && register_state.in_suggestion_mode {
|
||||||
register_state.in_suggestion_mode = false;
|
register_state.in_suggestion_mode = false;
|
||||||
register_state.show_role_suggestions = false;
|
register_state.show_role_suggestions = false;
|
||||||
register_state.selected_suggestion_index = None;
|
register_state.selected_suggestion_index = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute insert_char action based on the current view
|
|
||||||
let msg = if app_state.ui.show_login {
|
let msg = if app_state.ui.show_login {
|
||||||
auth_e::execute_edit_action(
|
auth_e::execute_edit_action(
|
||||||
"insert_char",
|
"insert_char",
|
||||||
key, // Pass the key event containing the char
|
key,
|
||||||
login_state,
|
login_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
@@ -255,7 +295,6 @@ pub async fn handle_edit_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
// Assuming FormState otherwise
|
|
||||||
form_e::execute_edit_action(
|
form_e::execute_edit_action(
|
||||||
"insert_char",
|
"insert_char",
|
||||||
key,
|
key,
|
||||||
@@ -267,7 +306,7 @@ pub async fn handle_edit_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
};
|
};
|
||||||
// Update role suggestions after insertion if needed (Register view)
|
|
||||||
if app_state.ui.show_register && register_state.current_field() == 4 {
|
if app_state.ui.show_register && register_state.current_field() == 4 {
|
||||||
register_state.update_role_suggestions();
|
register_state.update_role_suggestions();
|
||||||
}
|
}
|
||||||
@@ -277,7 +316,6 @@ pub async fn handle_edit_event(
|
|||||||
|
|
||||||
// --- Handle Backspace/Delete ---
|
// --- Handle Backspace/Delete ---
|
||||||
if matches!(key.code, KeyCode::Backspace | KeyCode::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 {
|
if app_state.ui.show_register && register_state.in_suggestion_mode {
|
||||||
register_state.in_suggestion_mode = false;
|
register_state.in_suggestion_mode = false;
|
||||||
register_state.show_role_suggestions = false;
|
register_state.show_role_suggestions = false;
|
||||||
@@ -290,7 +328,6 @@ pub async fn handle_edit_event(
|
|||||||
"delete_char_forward"
|
"delete_char_forward"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Execute delete action based on the current view
|
|
||||||
let result_msg: String = if app_state.ui.show_login {
|
let result_msg: String = if app_state.ui.show_login {
|
||||||
auth_e::execute_edit_action(
|
auth_e::execute_edit_action(
|
||||||
action_str,
|
action_str,
|
||||||
@@ -322,8 +359,7 @@ pub async fn handle_edit_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
// Assuming FormState otherwise
|
form_e::execute_edit_action(
|
||||||
form_e::execute_edit_action(
|
|
||||||
action_str,
|
action_str,
|
||||||
key,
|
key,
|
||||||
form_state,
|
form_state,
|
||||||
@@ -333,7 +369,7 @@ pub async fn handle_edit_event(
|
|||||||
total_count
|
total_count
|
||||||
).await?
|
).await?
|
||||||
};
|
};
|
||||||
// Update role suggestions after deletion if needed (Register view)
|
|
||||||
if app_state.ui.show_register && register_state.current_field() == 4 {
|
if app_state.ui.show_register && register_state.current_field() == 4 {
|
||||||
register_state.update_role_suggestions();
|
register_state.update_role_suggestions();
|
||||||
}
|
}
|
||||||
@@ -341,7 +377,5 @@ pub async fn handle_edit_event(
|
|||||||
return Ok(EditEventOutcome::Message(result_msg));
|
return Ok(EditEventOutcome::Message(result_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default return if no other handler matched
|
|
||||||
Ok(EditEventOutcome::Message("".to_string()))
|
Ok(EditEventOutcome::Message("".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user