From bb577bc27621e58a90d82a64316892a2f189be6f Mon Sep 17 00:00:00 2001 From: filipriec Date: Tue, 15 Apr 2025 16:23:26 +0200 Subject: [PATCH] now buffer handling is global but not allowed from edit mode --- client/config.toml | 6 ++-- client/src/modes/handlers/event.rs | 55 +++++++++++------------------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/client/config.toml b/client/config.toml index caa6bc6..c5eba7f 100644 --- a/client/config.toml +++ b/client/config.toml @@ -2,6 +2,8 @@ [keybindings] enter_command_mode = [":", "ctrl+;"] +next_buffer = ["ctrl+l"] +previous_buffer = ["ctrl+h"] [keybindings.general] move_up = ["k", "Up"] @@ -13,8 +15,6 @@ toggle_sidebar = ["ctrl+t"] toggle_buffer_list = ["ctrl+b"] next_field = ["Tab"] prev_field = ["Shift+Tab"] -next_buffer = ["ctrl+l"] -previous_buffer = ["ctrl+h"] [keybindings.common] save = ["ctrl+s"] @@ -36,8 +36,6 @@ enter_edit_mode_before = ["i"] enter_edit_mode_after = ["a"] previous_entry = ["left","q"] next_entry = ["right","1"] -next_buffer = ["ctrl+l"] -previous_buffer = ["ctrl+h"] move_left = ["h"] move_right = ["l"] diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index ba4d15b..e631f6b 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -135,6 +135,26 @@ impl EventHandler { ); return Ok(EventOutcome::Ok(message)); } + // --- Buffer Switching (Check Global) --- + if !matches!(current_mode, AppMode::Edit | AppMode::Command) { + if let Some(action) = config.get_action_for_key_in_mode( + &config.keybindings.global, key_code, modifiers // Check global bindings + ) { + match action { + "next_buffer" => { + if buffer::switch_buffer(buffer_state, true) { + return Ok(EventOutcome::Ok("Switched to next buffer".to_string())); + } + } + "previous_buffer" => { + if buffer::switch_buffer(buffer_state, false) { + return Ok(EventOutcome::Ok("Switched to previous buffer".to_string())); + } + } + _ => {} // Other global actions could be handled here if needed + } + } + } // --- End Global UI Toggles --- match current_mode { @@ -153,23 +173,6 @@ impl EventHandler { &mut self.command_message, ).await; match nav_outcome { - Ok(EventOutcome::Ok(ref msg)) if msg.is_empty() => { - if let Some(action) = config.get_general_action(key_code, modifiers) { - match action { - "next_buffer" => { - if buffer::switch_buffer(buffer_state, true) { - return Ok(EventOutcome::Ok("Switched to next buffer".to_string())); - } - } - "previous_buffer" => { - if buffer::switch_buffer(buffer_state, false) { - return Ok(EventOutcome::Ok("Switched to previous buffer".to_string())); - } - } - _ => {} - } - } - } Ok(EventOutcome::ButtonSelected { context, index }) => { let mut message = String::from("Selected"); // Default message match context { @@ -213,24 +216,6 @@ impl EventHandler { }, AppMode::ReadOnly => { - // --- Buffer Switching Check (ReadOnly Mode) --- - if let Some(action) = config.get_read_only_action_for_key(key_code, modifiers) { - match action { - "next_buffer" => { - if buffer::switch_buffer(buffer_state, true) { - return Ok(EventOutcome::Ok("Switched to next buffer".to_string())); - } - } - "previous_buffer" => { - if buffer::switch_buffer(buffer_state, false) { - return Ok(EventOutcome::Ok("Switched to previous buffer".to_string())); - } - } - _ => {} // Other read_only/common actions handled below - } - } - // --- End Buffer Switching Check --- - if config.is_enter_edit_mode_before(key_code, modifiers) && ModeManager::can_enter_edit_mode(current_mode) { self.is_edit_mode = true;