working switching of the buffers properly well now

This commit is contained in:
filipriec
2025-04-15 16:03:14 +02:00
parent c091a39802
commit 6267e3d593
6 changed files with 123 additions and 27 deletions

View File

@@ -1,2 +1,5 @@
// src/functions/common.rs
pub mod buffer;
pub use buffer::*;

View File

@@ -0,0 +1,26 @@
// src/functions/common/buffer.rs
use crate::state::app::buffer::BufferState;
/// Switches the active buffer index.
pub fn switch_buffer(buffer_state: &mut BufferState, next: bool) -> bool {
if buffer_state.history.len() <= 1 {
return false;
}
let len = buffer_state.history.len();
let current_index = buffer_state.active_index;
let new_index = if next {
(current_index + 1) % len
} else {
(current_index + len - 1) % len
};
if new_index != current_index {
buffer_state.active_index = new_index;
true
} else {
false
}
}