diff --git a/src/engines/mod.rs b/src/engines/mod.rs index 9388e10..3fec844 100644 --- a/src/engines/mod.rs +++ b/src/engines/mod.rs @@ -35,7 +35,6 @@ pub trait BrowserEngine { fn goto_url(&self, url: &Url); fn has_loaded(&self) -> bool; fn new_tab(&mut self, url: &Url) -> u32; - fn goto_tab(&mut self, id: u32); fn get_tabs(&self) -> &Tabs; fn get_tabs_mut(&mut self) -> &mut Tabs; @@ -140,7 +139,8 @@ impl Tabs { id } - pub fn remove(&mut self, id: u32) { + /// 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() { @@ -152,6 +152,7 @@ impl Tabs { } self.tabs.retain(|tab| tab.id != id); + self.current } pub fn get_current(&self) -> &Tab { diff --git a/src/widgets/browser_widgets.rs b/src/widgets/browser_widgets.rs index fe7d6e7..7fd0b74 100644 --- a/src/widgets/browser_widgets.rs +++ b/src/widgets/browser_widgets.rs @@ -151,20 +151,26 @@ where Message::SendMouseEvent(point, event) => { self.engine_mut().handle_mouse_event(point, event); } - Message::ChangeTab(index_type) => match index_type { - TabSelectionType::Id(id) => self.engine_mut().goto_tab(id), - TabSelectionType::Index(index) => { - let id = self.engine_mut().get_tabs().index_to_id(index); - self.engine_mut().goto_tab(id); - } - }, - Message::CloseTab(select_type) => match select_type { - TabSelectionType::Id(id) => self.engine_mut().get_tabs_mut().remove(id), - TabSelectionType::Index(index) => { - let id = self.engine_mut().get_tabs().index_to_id(index); - self.engine_mut().get_tabs_mut().remove(id); - } - }, + Message::ChangeTab(index_type) => { + let id = match index_type { + TabSelectionType::Id(id) => id, + TabSelectionType::Index(index) => { + self.engine_mut().get_tabs().index_to_id(index) + } + }; + self.engine_mut().get_tabs_mut().set_current_id(id); + self.url = self.engine().get_tabs().get_current().url(); + } + Message::CloseTab(index_type) => { + let id = match index_type { + TabSelectionType::Id(id) => id, + TabSelectionType::Index(index) => { + self.engine_mut().get_tabs().index_to_id(index) + } + }; + self.engine_mut().get_tabs_mut().remove(id); + self.url = self.engine().get_tabs().get_current().url(); + } Message::CreateTab => { self.url = self.home.to_string(); let home = self.home.clone();