working eidt mode perfectly well, i love it

This commit is contained in:
filipriec
2025-02-17 23:52:18 +01:00
parent 3864fc9ae1
commit 93968b2b2f
3 changed files with 27 additions and 11 deletions

View File

@@ -15,7 +15,14 @@ pub fn render_status_line(
theme: &Theme,
is_edit_mode: bool
) {
// // Create the status line text
// let status_line = Line::from(vec![
// Span::styled(current_dir, Style::default().fg(theme.fg)),
// Span::styled(
// program_info,
// Style::default().fg(theme.secondary).add_modifier(ratatui::style::Modifier::BOLD), // Use `secondary` color
// ),
// ]);
// Program name and version
let program_info = format!("multieko2 v{}", env!("CARGO_PKG_VERSION"));

View File

@@ -17,6 +17,10 @@ impl Config {
pub fn get_action_for_key(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
for (action, bindings) in &self.keybindings {
// Skip mode toggle actions
if action == "enter_edit_mode" || action == "exit_edit_mode" {
continue;
}
for binding in bindings {
if Self::matches_keybinding(binding, key, modifiers) {
return Some(action);
@@ -36,17 +40,13 @@ impl Config {
"ctrl" => expected_modifiers |= KeyModifiers::CONTROL,
"shift" => expected_modifiers |= KeyModifiers::SHIFT,
"alt" => expected_modifiers |= KeyModifiers::ALT,
_ => {
// Handle single character keys and special cases
expected_key = match part.to_lowercase().as_str() {
":" => Some(KeyCode::Char(':')),
"esc" => expected_key = Some(KeyCode::Esc),
":" => expected_key = Some(KeyCode::Char(':')),
part if part.len() == 1 => {
let c = part.chars().next().unwrap();
Some(KeyCode::Char(c))
}
_ => None,
};
expected_key = Some(KeyCode::Char(c));
}
_ => (),
}
}

View File

@@ -247,6 +247,15 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
current_field = (current_field + 1) % fields.len();
}
}
KeyCode::Esc => {
// Explicitly handle Esc even if not in command mode
if config.is_exit_edit_mode(key.code, key.modifiers) {
is_edit_mode = false;
edit_mode_cooldown = true;
command_message = "Read-only mode".to_string();
continue;
}
}
KeyCode::BackTab => current_field = current_field.saturating_sub(1),
KeyCode::Down => current_field = (current_field + 1) % fields.len(),
KeyCode::Up => current_field = current_field.saturating_sub(1),