modes needs more progress

This commit is contained in:
filipriec
2025-03-24 11:46:33 +01:00
parent ec5802b3a2
commit bdb6cd4069
2 changed files with 54 additions and 73 deletions

View File

@@ -35,7 +35,7 @@ next_entry = ["right","1"]
move_left = ["h"]
move_right = ["l"]
move_up = ["k", "Up"]
move_up = ["k"]
move_down = ["j"]
move_word_next = ["w"]
move_word_end = ["e"]

View File

@@ -62,7 +62,7 @@ impl EventHandler {
// Handle common actions across all modes
if UiStateHandler::toggle_sidebar(&mut app_state.ui, config, key_code, modifiers) {
return Ok((false, format!("Sidebar {}",
return Ok((false, format!("Sidebar {}",
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
)));
}
@@ -71,16 +71,16 @@ impl EventHandler {
match current_mode {
AppMode::General => {
return self.handle_general_mode(
key,
config,
key,
config,
form_state,
app_state,
);
},
AppMode::ReadOnly => {
// Check for mode transitions first
if config.is_enter_edit_mode_before(key_code, modifiers) &&
if config.is_enter_edit_mode_before(key_code, modifiers) &&
ModeManager::can_enter_edit_mode(current_mode) {
self.is_edit_mode = true;
self.edit_mode_cooldown = true;
@@ -88,8 +88,8 @@ impl EventHandler {
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
return Ok((false, self.command_message.clone()));
}
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) {
let current_input = form_state.get_current_input();
if !current_input.is_empty() && form_state.current_cursor_pos < current_input.len() {
@@ -102,7 +102,7 @@ impl EventHandler {
terminal.set_cursor_style(SetCursorStyle::BlinkingBar)?;
return Ok((false, self.command_message.clone()));
}
// Check for entering command mode
if let Some(action) = config.get_read_only_action_for_key(key_code, modifiers) {
if action == "enter_command_mode" && ModeManager::can_enter_command_mode(current_mode) {
@@ -112,26 +112,32 @@ impl EventHandler {
return Ok((false, String::new()));
}
}
// Handle common actions
// 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(
&config.keybindings.common,
key_code,
modifiers
) {
return self.handle_common_action(
action,
form_state,
grpc_client,
command_handler,
terminal,
app_state,
current_position,
total_count,
).await;
match action {
"save" | "force_quit" | "save_and_quit" | "revert" => {
return self.handle_core_action(
action,
form_state,
grpc_client,
command_handler,
terminal,
app_state,
current_position,
total_count,
).await;
},
_ => {} // For other actions, let the mode-specific handler take care of it
}
}
// Handle read-only mode specific actions
// Let read_only mode handle its own actions (including navigation from common bindings)
return read_only::handle_read_only_event(
key,
config,
@@ -145,7 +151,7 @@ impl EventHandler {
&mut self.ideal_cursor_column,
).await;
},
AppMode::Edit => {
// Check for exiting edit mode
if config.is_exit_edit_mode(key_code, modifiers) {
@@ -165,26 +171,32 @@ impl EventHandler {
}
return Ok((false, self.command_message.clone()));
}
// Handle common actions
// 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(
&config.keybindings.common,
key_code,
modifiers
) {
return self.handle_common_action(
action,
form_state,
grpc_client,
command_handler,
terminal,
app_state,
current_position,
total_count,
).await;
match action {
"save" | "force_quit" | "save_and_quit" | "revert" => {
return self.handle_core_action(
action,
form_state,
grpc_client,
command_handler,
terminal,
app_state,
current_position,
total_count,
).await;
},
_ => {} // For other actions, let the mode-specific handler take care of it
}
}
// Handle edit mode actions
// Let edit mode handle its own actions (including navigation from common bindings)
let result = edit::handle_edit_event_internal(
key,
config,
@@ -200,7 +212,7 @@ impl EventHandler {
self.key_sequence_tracker.reset();
return Ok((false, result));
},
AppMode::Command => {
let (should_exit, message, exit_command_mode) = command_mode::handle_command_event(
key,
@@ -287,8 +299,8 @@ impl EventHandler {
Ok((false, String::new()))
}
// Helper method for handling common actions across modes
async fn handle_common_action(
// Helper method for handling core application actions (not navigation)
async fn handle_core_action(
&mut self,
action: &str,
form_state: &mut FormState,
@@ -327,39 +339,8 @@ impl EventHandler {
).await?;
Ok((false, message))
},
"move_up" => {
if form_state.current_field == 0 {
form_state.current_field = form_state.fields.len() - 1;
} else {
form_state.current_field = form_state.current_field.saturating_sub(1);
}
let current_input = form_state.get_current_input();
let max_cursor_pos = if !current_input.is_empty() {
current_input.len() - 1
} else {
0
};
form_state.current_cursor_pos = self.ideal_cursor_column.min(max_cursor_pos);
Ok((false, String::new()))
},
"move_down" => {
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
let current_input = form_state.get_current_input();
let max_cursor_pos = if !current_input.is_empty() {
current_input.len() - 1
} else {
0
};
form_state.current_cursor_pos = self.ideal_cursor_column.min(max_cursor_pos);
Ok((false, String::new()))
},
"toggle_sidebar" => {
navigation::toggle_sidebar(app_state);
Ok((false, format!("Sidebar {}",
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
)))
},
_ => Ok((false, format!("Unknown common action: {}", action))),
// We should never hit this case given our filtering above
_ => Ok((false, format!("Core action not handled: {}", action))),
}
}
}