buffer movement is now working as I would only wish it would. Needs layers implementation, will do in the future

This commit is contained in:
filipriec
2025-04-15 00:10:28 +02:00
parent aa8887318f
commit 779683de4b
2 changed files with 16 additions and 4 deletions

View File

@@ -48,7 +48,7 @@ pub fn render_buffer_list(
let mut current_width = 0;
for (i, view) in history.iter().enumerate() {
let is_active = i == history_len - 1;
let is_active = i == app_state.ui.active_buffer_index;
let buffer_name = view.display_name();
let buffer_text = format!(" {} ", buffer_name);
let text_width = UnicodeWidthStr::width(buffer_text.as_str());
@@ -60,6 +60,7 @@ pub fn render_buffer_list(
}
if i > 0 {
let prev_is_active = i - 1 == app_state.ui.active_buffer_index;
let sep_style = if is_active {
separator_style_inactive_to_active
} else {
@@ -73,6 +74,7 @@ pub fn render_buffer_list(
spans.push(Span::styled(buffer_text, text_style));
current_width += text_width;
let next_is_active = i + 1 < history_len && i + 1 == app_state.ui.active_buffer_index;
let sep_style = if is_active {
separator_style_active_to_inactive
} else {

View File

@@ -49,6 +49,7 @@ pub struct UiState {
pub show_register: bool,
pub focus_outside_canvas: bool,
pub buffer_history: Vec<AppView>,
pub active_buffer_index: usize,
pub dialog: DialogState,
}
@@ -166,6 +167,7 @@ impl Default for UiState {
show_buffer_list: false,
focus_outside_canvas: false,
buffer_history: vec![AppView::Intro],
active_buffer_index: 0,
dialog: DialogState::default(),
}
}
@@ -186,10 +188,18 @@ impl Default for DialogState {
}
impl UiState {
/// Adds the given view to the history if it's different from the last one.
/// Updates the buffer history and active index.
pub fn update_buffer_history(&mut self, view: AppView) {
if self.buffer_history.last() != Some(&view) {
self.buffer_history.push(view.clone());
let existing_pos = self.buffer_history.iter().position(|v| v == &view);
match existing_pos {
Some(pos) => {
self.active_buffer_index = pos;
}
None => {
self.buffer_history.push(view.clone());
self.active_buffer_index = self.buffer_history.len() - 1;
}
}
}
}