Add pinned tab controls

This commit is contained in:
2026-05-07 19:47:27 -04:00
parent 0f372c5fc0
commit 82df2b4502
8 changed files with 163 additions and 2 deletions
+22
View File
@@ -32,6 +32,7 @@ impl InitialBrowserConfig {
pub struct BrowserSnapshot {
pub tabs: Vec<BrowserTab>,
pub favorites: Vec<BrowserTab>,
pub pinned_tabs: Vec<BrowserTab>,
pub active_tab_id: TabId,
pub active_space_name: String,
pub active_profile_name: String,
@@ -155,6 +156,14 @@ impl BrowserCore {
Ok(next_favorite)
}
pub fn toggle_active_tab_pinned(&mut self) -> Result<bool, CoreError> {
let active_index = self.active_tab_index()?;
let active_tab = self.tabs.get_mut(active_index).ok_or(CoreError::MissingActiveTab)?;
let next_pinned = !active_tab.flags().pinned;
active_tab.set_pinned(next_pinned);
Ok(next_pinned)
}
pub fn set_command_query(&mut self, query: impl Into<String>) {
self.command_query = query.into();
}
@@ -211,6 +220,7 @@ impl BrowserCore {
Ok(BrowserSnapshot {
favorites: self.favorites(),
pinned_tabs: self.pinned_tabs(),
tabs: self.tabs.clone(),
active_tab_id: self.active_tab_id.clone(),
active_space_name: active_space.name().to_string(),
@@ -249,6 +259,10 @@ impl BrowserCore {
self.toggle_active_tab_favorite()?;
Ok(true)
}
"pin" | "pin-tab" | "toggle-pin" => {
self.toggle_active_tab_pinned()?;
Ok(true)
}
_ => Ok(false),
}
}
@@ -264,6 +278,14 @@ impl BrowserCore {
self.tabs.iter().filter(|tab| tab.flags().favorite).cloned().collect()
}
fn pinned_tabs(&self) -> Vec<BrowserTab> {
self.tabs
.iter()
.filter(|tab| tab.flags().pinned && !tab.flags().favorite)
.cloned()
.collect()
}
fn find_tab_match(&self, query: &str) -> Option<TabId> {
let normalized_query = query.trim().to_lowercase();
self.tabs
+15
View File
@@ -18,6 +18,21 @@ fn favorite_command_toggles_active_tab() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn pin_command_toggles_active_tab() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.set_command_query(">pin");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(intent, Some(CommandIntent::Command("pin".to_string())));
assert_eq!(snapshot.pinned_tabs.len(), 1);
assert_eq!(snapshot.pinned_tabs[0].id(), &snapshot.active_tab_id);
assert_eq!(snapshot.command_query, "");
Ok(())
}
#[test]
fn new_tab_command_opens_new_tab() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
+32
View File
@@ -155,6 +155,38 @@ fn toggles_active_tab_favorite() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn toggles_active_tab_pinned() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let pinned = core.toggle_active_tab_pinned()?;
let snapshot = core.snapshot()?;
assert!(pinned);
assert_eq!(snapshot.pinned_tabs.len(), 1);
assert_eq!(snapshot.pinned_tabs[0].id(), &snapshot.active_tab_id);
let pinned = core.toggle_active_tab_pinned()?;
let snapshot = core.snapshot()?;
assert!(!pinned);
assert!(snapshot.pinned_tabs.is_empty());
Ok(())
}
#[test]
fn favorite_tabs_are_omitted_from_pinned_section() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.toggle_active_tab_pinned()?;
core.toggle_active_tab_favorite()?;
let snapshot = core.snapshot()?;
assert_eq!(snapshot.favorites.len(), 1);
assert!(snapshot.pinned_tabs.is_empty());
Ok(())
}
#[test]
fn enforces_default_favorite_limit() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;