From 681b952b139d47685ad143426dac996015922463 Mon Sep 17 00:00:00 2001 From: Redhawk18 Date: Tue, 19 Mar 2024 20:14:00 -0400 Subject: [PATCH] fixed bug where active tab index could be bigger than the data array that holds it --- gui/src/lib.rs | 9 ++++++++- gui/src/widgets/tab_bar.rs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gui/src/lib.rs b/gui/src/lib.rs index a6e6a74..3d75e08 100644 --- a/gui/src/lib.rs +++ b/gui/src/lib.rs @@ -217,8 +217,15 @@ impl Application for Blaze { pane_state.active_tab_index = 0; } + // current we arent removing the data from the program, just removing it from being visable. This is a memory leak pane_state.data.remove(id); - // current we arent removing the data from the program, just removing it from being visable + + // set the new active tab index + if pane_state.data.is_empty() { + pane_state.active_tab_index = 0; + } else { + pane_state.active_tab_index = pane_state.data.len() - 1; + } } Message::PaneDragged(DragEvent::Dropped { pane, target }) => { diff --git a/gui/src/widgets/tab_bar.rs b/gui/src/widgets/tab_bar.rs index c6ae3c8..97c366a 100644 --- a/gui/src/widgets/tab_bar.rs +++ b/gui/src/widgets/tab_bar.rs @@ -50,7 +50,7 @@ fn head(active: usize, data: &[&Buffer]) -> TabBar(active: usize, data: &[&'a Buffer]) -> Element<'a, Message> { - let active_tab = data.get(active).unwrap(); //wrong + let active_tab = data.get(active).expect("There is no active tab"); match active_tab { Buffer::File(file_buffer) => text_editor(&file_buffer.content)