Skip to content

Commit

Permalink
change url when switching or removing tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
LegitCamper committed Aug 18, 2024
1 parent 0dd3f5e commit e1107c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::TabInfo>;
fn get_tabs_mut(&mut self) -> &mut Tabs<Self::TabInfo>;

Expand Down Expand Up @@ -140,7 +139,8 @@ impl<TabInfo> Tabs<TabInfo> {
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() {
Expand All @@ -152,6 +152,7 @@ impl<TabInfo> Tabs<TabInfo> {
}

self.tabs.retain(|tab| tab.id != id);
self.current
}

pub fn get_current(&self) -> &Tab<TabInfo> {
Expand Down
34 changes: 20 additions & 14 deletions src/widgets/browser_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e1107c5

Please sign in to comment.