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_left = ["h"]
move_right = ["l"] move_right = ["l"]
move_up = ["k", "Up"] move_up = ["k"]
move_down = ["j"] move_down = ["j"]
move_word_next = ["w"] move_word_next = ["w"]
move_word_end = ["e"] move_word_end = ["e"]

View File

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