From 20e71e20addbc6ebeee6b148e423856554542e17 Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Sun, 18 Aug 2024 20:28:47 -0600 Subject: [PATCH] add tab history --- src/engines/mod.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/engines/mod.rs b/src/engines/mod.rs index ec7b5a0..3ab0519 100644 --- a/src/engines/mod.rs +++ b/src/engines/mod.rs @@ -97,7 +97,7 @@ impl Tab { pub struct Tabs { tabs: Vec>, - current: u32, + history: Vec, } impl Default for Tabs { @@ -110,7 +110,7 @@ impl Tabs { pub fn new() -> Self { Self { tabs: Vec::new(), - current: 0, + history: Vec::new(), } } @@ -131,11 +131,14 @@ impl Tabs { } pub fn get_current_id(&self) -> u32 { - self.current + self.history + .last() + .expect("No tab in history to get current from") + .to_owned() } pub fn set_current_id(&mut self, id: u32) { - self.current = id + self.history.push(id) } pub fn tabs(&self) -> &Vec> { @@ -150,26 +153,18 @@ impl Tabs { /// Returns the newly active tab pub fn remove(&mut self, id: u32) -> u32 { - // TODO: have list of prevous tabs instead - if self.current == id { - for tab in self.tabs.iter().rev() { - if tab.id != id { - self.current = tab.id; - break; - } - } - } + self.history.retain(|tab_id| *tab_id != id); self.tabs.retain(|tab| tab.id != id); - self.current + self.get_current_id() } pub fn get_current(&self) -> &Tab { - self.get(self.current) + self.get(self.get_current_id()) } pub fn get_current_mut(&mut self) -> &mut Tab { - self.get_mut(self.current) + self.get_mut(self.get_current_id()) } pub fn get(&self, id: u32) -> &Tab {