From b08b9236d7a9d1e5c90a8d5983c3a6a1e21733ae Mon Sep 17 00:00:00 2001 From: sawyer bristol Date: Sun, 18 Aug 2024 14:48:21 -0600 Subject: [PATCH] change url when switching or removing tabs remove uneeded engine command --- src/engines/mod.rs | 5 +++-- src/engines/ultralight.rs | 4 ---- src/widgets/browser_widgets.rs | 34 ++++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 20 deletions(-) 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/engines/ultralight.rs b/src/engines/ultralight.rs index 6a69c37..25637a0 100644 --- a/src/engines/ultralight.rs +++ b/src/engines/ultralight.rs @@ -233,10 +233,6 @@ impl BrowserEngine for Ultralight { return id; } - fn goto_tab(&mut self, id: u32) { - self.tabs.current = id - } - fn refresh(&self) { self.tabs.get_current().tab_info.view.reload(); } 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();