Add space switching shortcuts
This commit is contained in:
@@ -229,6 +229,32 @@ impl BrowserCore {
|
||||
Ok(tab_id)
|
||||
}
|
||||
|
||||
pub fn select_next_space(&mut self) -> Result<TabId, CoreError> {
|
||||
let spaces = self.sorted_spaces();
|
||||
let Some(active_index) =
|
||||
spaces.iter().position(|space| space.id() == &self.active_space_id)
|
||||
else {
|
||||
return Err(CoreError::SpaceNotFound { id: self.active_space_id.clone() });
|
||||
};
|
||||
|
||||
let next_index = (active_index + 1) % spaces.len();
|
||||
let space_id = spaces[next_index].id().clone();
|
||||
self.select_space(&space_id)
|
||||
}
|
||||
|
||||
pub fn select_previous_space(&mut self) -> Result<TabId, CoreError> {
|
||||
let spaces = self.sorted_spaces();
|
||||
let Some(active_index) =
|
||||
spaces.iter().position(|space| space.id() == &self.active_space_id)
|
||||
else {
|
||||
return Err(CoreError::SpaceNotFound { id: self.active_space_id.clone() });
|
||||
};
|
||||
|
||||
let previous_index = if active_index == 0 { spaces.len() - 1 } else { active_index - 1 };
|
||||
let space_id = spaces[previous_index].id().clone();
|
||||
self.select_space(&space_id)
|
||||
}
|
||||
|
||||
pub fn set_active_space_archive_policy(
|
||||
&mut self,
|
||||
archive_policy: ArchivePolicy,
|
||||
|
||||
@@ -152,6 +152,29 @@ fn space_sidebar_width_updates_selected_space() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selecting_adjacent_spaces_uses_sort_order_with_wraparound() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let work_space_id = core.snapshot()?.active_space_id;
|
||||
let research_space_id = core.create_space("Research", "R", 0x9fc9a2)?;
|
||||
let personal_space_id = core.create_space("Personal", "P", 0x8eb7d4)?;
|
||||
|
||||
core.set_space_sort_key(&work_space_id, 20)?;
|
||||
core.set_space_sort_key(&research_space_id, 10)?;
|
||||
core.set_space_sort_key(&personal_space_id, 30)?;
|
||||
core.select_space(&work_space_id)?;
|
||||
|
||||
core.select_next_space()?;
|
||||
assert_eq!(core.snapshot()?.active_space_id, personal_space_id);
|
||||
|
||||
core.select_next_space()?;
|
||||
assert_eq!(core.snapshot()?.active_space_id, research_space_id);
|
||||
|
||||
core.select_previous_space()?;
|
||||
assert_eq!(core.snapshot()?.active_space_id, personal_space_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn active_space_updated_at(
|
||||
core: &BrowserCore,
|
||||
space_id: &ely_domain::SpaceId,
|
||||
|
||||
Reference in New Issue
Block a user