Skip to content

Commit

Permalink
fixed bug where active tab index could be bigger than the data array …
Browse files Browse the repository at this point in the history
…that holds it
  • Loading branch information
Redhawk18 committed Mar 20, 2024
1 parent 88133e0 commit 681b952
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/widgets/tab_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn head(active: usize, data: &[&Buffer]) -> TabBar<Message, usize, Theme, Render
}

fn body<'a>(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)
Expand Down

0 comments on commit 681b952

Please sign in to comment.