Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

Add collection Spaces: local-only Spaces holding thread references

RoversXe371b5b27474
diff --git a/wezterm-gui/i18n/en-US.ftl b/wezterm-gui/i18n/en-US.ftl
index 0aa03eff..122d0bc9 100644
--- a/wezterm-gui/i18n/en-US.ftl
+++ b/wezterm-gui/i18n/en-US.ftl
@@ -182,6 +182,7 @@ sidebar-connecting = Connecting…
sidebar-reconnect = Reconnect
sidebar-new-thread = New Thread
sidebar-pinned = Pinned
+sidebar-collection-threads = Threads
sidebar-workspaces = Workspaces
sidebar-settings = Settings
menu-rename-project = Rename Project…
@@ -197,6 +198,11 @@ menu-space-server-group-connecting = { $name } (connecting…)
menu-space-server-group-reconnecting = { $name } (reconnecting…)
remote-tree-mutation-offline = { $name } is disconnected. Reconnect and try again.
menu-new-space-here = New Space Here
+menu-new-collection-space = New Collection Space
+menu-add-to-collection = Add to Collection
+menu-add-to-collection-named = Add to “{ $name }”
+menu-remove-from-collection = Remove from Collection
+menu-go-to-origin-space = Go to Origin Space
menu-rename-space = Rename Space…
menu-rename-named-space = Rename “{ $name }”…
menu-disconnect-space = Disconnect “{ $name }” (Server Keeps Running)
diff --git a/wezterm-gui/i18n/fr-FR.ftl b/wezterm-gui/i18n/fr-FR.ftl
index 625bdf49..66c292d8 100644
--- a/wezterm-gui/i18n/fr-FR.ftl
+++ b/wezterm-gui/i18n/fr-FR.ftl
@@ -182,6 +182,7 @@ sidebar-connecting = Connexion…
sidebar-reconnect = Reconnecter
sidebar-new-thread = Nouvelle session
sidebar-pinned = Épinglées
+sidebar-collection-threads = Sessions
sidebar-workspaces = Espaces de travail
sidebar-settings = Réglages
menu-rename-project = Renommer le projet…
@@ -197,6 +198,11 @@ menu-space-server-group-connecting = { $name } (connexion…)
menu-space-server-group-reconnecting = { $name } (reconnexion…)
remote-tree-mutation-offline = { $name } est déconnecté. Reconnectez-vous et réessayez.
menu-new-space-here = Nouvel espace ici
+menu-new-collection-space = Nouvel espace collection
+menu-add-to-collection = Ajouter à la collection
+menu-add-to-collection-named = Ajouter à « { $name } »
+menu-remove-from-collection = Retirer de la collection
+menu-go-to-origin-space = Aller à l’espace d’origine
menu-rename-space = Renommer l’espace…
menu-rename-named-space = Renommer « { $name } »…
menu-disconnect-space = Déconnecter « { $name } » (le serveur reste actif)
diff --git a/wezterm-gui/i18n/ja-JP.ftl b/wezterm-gui/i18n/ja-JP.ftl
index 041bf305..7f553bce 100644
--- a/wezterm-gui/i18n/ja-JP.ftl
+++ b/wezterm-gui/i18n/ja-JP.ftl
@@ -182,6 +182,7 @@ sidebar-connecting = 接続中…
sidebar-reconnect = 再接続
sidebar-new-thread = 新しいセッション
sidebar-pinned = ピン留め
+sidebar-collection-threads = セッション
sidebar-workspaces = ワークスペース
sidebar-settings = 設定
menu-rename-project = プロジェクト名を変更…
@@ -197,6 +198,11 @@ menu-space-server-group-connecting = { $name }(接続中…)
menu-space-server-group-reconnecting = { $name }(再接続中…)
remote-tree-mutation-offline = { $name } は切断されています。再接続してからもう一度お試しください。
menu-new-space-here = このサーバーに新しいスペース
+menu-new-collection-space = 新規コレクションスペース
+menu-add-to-collection = コレクションに追加
+menu-add-to-collection-named = “{ $name }”に追加
+menu-remove-from-collection = コレクションから削除
+menu-go-to-origin-space = 元のスペースへ移動
menu-rename-space = スペース名を変更…
menu-rename-named-space = 「{ $name }」の名前を変更…
menu-disconnect-space = 「{ $name }」を切断(サーバーは実行を継続)
diff --git a/wezterm-gui/i18n/zh-CN.ftl b/wezterm-gui/i18n/zh-CN.ftl
index a7f43fc1..b0ca6be2 100644
--- a/wezterm-gui/i18n/zh-CN.ftl
+++ b/wezterm-gui/i18n/zh-CN.ftl
@@ -182,6 +182,7 @@ sidebar-connecting = 正在连接…
sidebar-reconnect = 重新连接
sidebar-new-thread = 新建会话
sidebar-pinned = 已置顶
+sidebar-collection-threads = 会话
sidebar-workspaces = 工作区
sidebar-settings = 设置
menu-rename-project = 重命名项目…
@@ -197,6 +198,11 @@ menu-space-server-group-connecting = { $name }(连接中…)
menu-space-server-group-reconnecting = { $name }(重连中…)
remote-tree-mutation-offline = { $name } 已断开。请重新连接后再试。
menu-new-space-here = 在此服务器新建空间
+menu-new-collection-space = 新建集合空间
+menu-add-to-collection = 添加到集合
+menu-add-to-collection-named = 添加到“{ $name }”
+menu-remove-from-collection = 从集合移除
+menu-go-to-origin-space = 回到原空间
menu-rename-space = 重命名空间…
menu-rename-named-space = 重命名“{ $name }”…
menu-disconnect-space = 断开“{ $name }”(服务器继续运行)
diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs
index 9d4adbcd..eb06fa25 100644
--- a/wezterm-gui/src/frontend.rs
+++ b/wezterm-gui/src/frontend.rs
@@ -715,10 +715,11 @@ impl GuiFrontEnd {
let thread_id = crate::workspace_threads::ensure_active_thread_for_space(space_id)
.ok_or_else(|| anyhow!("failed to ensure active thread for Space {space_id}"))?;
let live_workspaces = mux.iter_workspaces();
- let plan = crate::workspace_threads::activate_thread_record(&thread_id, &live_workspaces)
- .ok_or_else(|| {
- anyhow!("failed to activate thread {thread_id} for Space {space_id}")
- })?;
+ let plan =
+ crate::workspace_threads::activate_thread_record(&thread_id, &live_workspaces, true)
+ .ok_or_else(|| {
+ anyhow!("failed to activate thread {thread_id} for Space {space_id}")
+ })?;
let created_mux_window = plan.needs_materialize;
if plan.needs_materialize {
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index b98ffa2e..8804aa71 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -430,6 +430,19 @@ pub(crate) enum ContextMenuApplicationAction {
},
/// Sidebar view-options: show/hide threads with this work status.
ToggleWorkspaceStatusFilter(crate::workspace_threads::WorkspaceThreadWorkStatus),
+ /// Add a thread reference to a collection Space; `None` creates the
+ /// first collection Space and adds there.
+ AddThreadToCollection {
+ collection_space_id: Option<String>,
+ thread_id: String,
+ },
+ /// Drop a thread reference from a collection Space.
+ RemoveThreadFromCollection {
+ collection_space_id: String,
+ thread_id: String,
+ },
+ /// Space menu: create a collection Space and switch to it.
+ CreateCollectionSpace,
/// Fetch a file from the remote Files panel into the Downloads folder.
DownloadRemoteFile {
path: remote_files::RemotePath,
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index adf6f2bc..6d7ed799 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -2803,7 +2803,15 @@ impl super::TermWindow {
let rows: Vec<(String, isize, isize)> = match &kind {
super::SidebarRowKind::Project(_) => project_block_extents(&self.ui_items),
super::SidebarRowKind::Thread { project_id, .. } => {
- let siblings = crate::workspace_threads::unpinned_thread_ids(project_id);
+ // In a collection Space the visible list is the reference
+ // list, not the origin project's threads.
+ let siblings = if crate::workspace_threads::is_collection_space(
+ &self.active_space_id,
+ ) {
+ crate::workspace_threads::collection_thread_refs(&self.active_space_id)
+ } else {
+ crate::workspace_threads::unpinned_thread_ids(project_id)
+ };
self.ui_items
.iter()
.filter_map(|candidate| match &candidate.item_type {
@@ -2844,7 +2852,13 @@ impl super::TermWindow {
crate::workspace_threads::ordered_project_ids(&self.active_space_id)
}
super::SidebarRowKind::Thread { project_id, .. } => {
- crate::workspace_threads::unpinned_thread_ids(project_id)
+ if crate::workspace_threads::is_collection_space(&self.active_space_id) {
+ crate::workspace_threads::collection_thread_refs(
+ &self.active_space_id,
+ )
+ } else {
+ crate::workspace_threads::unpinned_thread_ids(project_id)
+ }
}
};
let before = clamp_end_anchor_to_next_logical_sibling(
@@ -2882,11 +2896,24 @@ impl super::TermWindow {
super::SidebarRowKind::Thread {
thread_id,
project_id,
- } => crate::workspace_threads::move_thread_before(
- project_id,
- thread_id,
- target.before.as_deref(),
- ),
+ } => {
+ let space_id = self.active_space_id.clone();
+ if crate::workspace_threads::is_collection_space(&space_id) {
+ // Reference order is purely local; nothing travels to
+ // any server.
+ crate::workspace_threads::move_thread_ref_before(
+ &space_id,
+ thread_id,
+ target.before.as_deref(),
+ )
+ } else {
+ crate::workspace_threads::move_thread_before(
+ project_id,
+ thread_id,
+ target.before.as_deref(),
+ )
+ }
+ }
};
if changed {
context.invalidate();
@@ -4665,10 +4692,12 @@ impl super::TermWindow {
item.x as isize,
item.y.saturating_add(item.height) as isize,
);
- self.show_term_context_menu(context, coords, self.space_menu_items());
+ let items = self.space_menu_items();
+ self.show_term_context_menu(context, coords, items);
}
WMEK::Press(MousePress::Right) => {
- self.show_term_context_menu(context, event.coords, self.space_menu_items());
+ let items = self.space_menu_items();
+ self.show_term_context_menu(context, event.coords, items);
}
_ => {}
}
@@ -4747,7 +4776,11 @@ impl super::TermWindow {
else {
return;
};
- let draggable = !crate::workspace_threads::thread_is_pinned(&thread_id);
+ // Collection rows reorder the local reference list, so the
+ // origin thread's pinned state is irrelevant there.
+ let draggable = crate::workspace_threads::is_collection_space(
+ &self.active_space_id,
+ ) || !crate::workspace_threads::thread_is_pinned(&thread_id);
let title = crate::workspace_threads::thread_name(&thread_id)
.unwrap_or_else(|| thread_id.clone());
self.arm_sidebar_row_drag(
@@ -4762,11 +4795,8 @@ impl super::TermWindow {
);
}
WMEK::Press(MousePress::Right) => {
- self.show_term_context_menu(
- context,
- event.coords,
- self.workspace_thread_context_menu_items(&thread_id),
- );
+ let items = self.workspace_thread_context_menu_items(&thread_id);
+ self.show_term_context_menu(context, event.coords, items);
}
_ => {}
}
@@ -4785,11 +4815,8 @@ impl super::TermWindow {
context.invalidate();
}
WMEK::Press(MousePress::Right) => {
- self.show_term_context_menu(
- context,
- event.coords,
- self.workspace_thread_context_menu_items(&thread_id),
- );
+ let items = self.workspace_thread_context_menu_items(&thread_id);
+ self.show_term_context_menu(context, event.coords, items);
}
_ => {}
}
@@ -4804,14 +4831,20 @@ impl super::TermWindow {
) {
match event.kind {
WMEK::Press(MousePress::Left) => {
- self.end_workspace_thread(&thread_id, Some(context));
+ // In a collection Space the X removes the reference; the
+ // thread itself keeps living in its origin Space.
+ let space_id = self.active_space_id.clone();
+ if crate::workspace_threads::is_collection_space(&space_id) {
+ if crate::workspace_threads::remove_thread_ref(&space_id, &thread_id) {
+ context.invalidate();
+ }
+ } else {
+ self.end_workspace_thread(&thread_id, Some(context));
+ }
}
WMEK::Press(MousePress::Right) => {
- self.show_term_context_menu(
- context,
- event.coords,
- self.workspace_thread_context_menu_items(&thread_id),
- );
+ let items = self.workspace_thread_context_menu_items(&thread_id);
+ self.show_term_context_menu(context, event.coords, items);
}
_ => {}
}
@@ -4977,7 +5010,8 @@ impl super::TermWindow {
/// header carrying the connection's state, with its Spaces listed beneath
/// and a "New Space Here" entry of its own. Local Spaces stay at the top,
/// ungrouped.
- fn space_menu_items(&self) -> Vec<ContextMenuItem> {
+ fn space_menu_items(&mut self) -> Vec<ContextMenuItem> {
+ self.begin_context_menu_application_actions();
let spaces = crate::workspace_threads::spaces_for_window(self.space_owner_id);
let space_item = |space: &crate::workspace_threads::SpaceView| {
@@ -5062,6 +5096,13 @@ impl super::TermWindow {
ContextMenuIcon::New,
KeyAssignment::CreateSpace,
));
+ let new_collection_item = self.context_menu_application_item_with_icon(
+ crate::i18n::tr("menu-new-collection-space"),
+ ContextMenuIcon::Pin,
+ crate::termwindow::ContextMenuApplicationAction::CreateCollectionSpace,
+ true,
+ );
+ items.push(new_collection_item);
items.push(ContextMenuItem::item_with_icon(
spaces
.iter()
@@ -5341,9 +5382,13 @@ impl super::TermWindow {
true
}
- fn workspace_thread_context_menu_items(&self, thread_id: &str) -> Vec<ContextMenuItem> {
+ fn workspace_thread_context_menu_items(&mut self, thread_id: &str) -> Vec<ContextMenuItem> {
+ self.begin_context_menu_application_actions();
let thread_id = thread_id.to_string();
let is_pinned = crate::workspace_threads::thread_is_pinned(&thread_id);
+ let active_space = self.active_space_id.clone();
+ let is_collection_ref = crate::workspace_threads::is_collection_space(&active_space)
+ && crate::workspace_threads::thread_ref_exists(&active_space, &thread_id);
let live_workspaces = Mux::get().iter_workspaces();
let connection =
crate::workspace_threads::thread_connection_state(&thread_id, &live_workspaces);
@@ -5372,8 +5417,13 @@ impl super::TermWindow {
}
}
- items.extend([
- ContextMenuItem::item_with_icon(
+ // On a reference row the pin toggle and Delete would mutate the
+ // origin thread while reading like row actions — the reference is
+ // removed via "Remove from Collection" below instead. Rename and
+ // Mark Unread act on the real thread on purpose: a reference is a
+ // shortcut to it, not a copy.
+ if !is_collection_ref {
+ items.push(ContextMenuItem::item_with_icon(
if is_pinned {
crate::i18n::tr("menu-unpin-thread")
} else {
@@ -5385,23 +5435,83 @@ impl super::TermWindow {
ContextMenuIcon::Pin
},
KeyAssignment::ToggleWorkspaceThreadPinned(thread_id.clone()),
- ),
- ContextMenuItem::item_with_icon(
- crate::i18n::tr("menu-rename-thread"),
- ContextMenuIcon::Edit,
- KeyAssignment::PromptRenameWorkspaceThread(thread_id.clone()),
- ),
- ContextMenuItem::item_with_icon(
+ ));
+ }
+ items.push(ContextMenuItem::item_with_icon(
+ crate::i18n::tr("menu-rename-thread"),
+ ContextMenuIcon::Edit,
+ KeyAssignment::PromptRenameWorkspaceThread(thread_id.clone()),
+ ));
+ if !is_collection_ref {
+ items.push(ContextMenuItem::item_with_icon(
crate::i18n::tr("menu-delete-thread"),
ContextMenuIcon::Delete,
KeyAssignment::DeleteWorkspaceThread(thread_id.clone()),
- ),
- ContextMenuItem::item_with_icon(
- crate::i18n::tr("menu-mark-unread"),
- ContextMenuIcon::Notification,
- KeyAssignment::MarkWorkspaceThreadUnread(thread_id),
- ),
- ]);
+ ));
+ }
+ items.push(ContextMenuItem::item_with_icon(
+ crate::i18n::tr("menu-mark-unread"),
+ ContextMenuIcon::Notification,
+ KeyAssignment::MarkWorkspaceThreadUnread(thread_id.clone()),
+ ));
+
+ // Collection Space section. Inside a collection the row is a
+ // reference, so it can be removed here or traced back to its origin;
+ // everywhere else the thread can be added to a collection.
+ items.push(ContextMenuItem::Separator);
+ if is_collection_ref {
+ let remove_item = self.context_menu_application_item_with_icon(
+ crate::i18n::tr("menu-remove-from-collection"),
+ ContextMenuIcon::Close,
+ crate::termwindow::ContextMenuApplicationAction::RemoveThreadFromCollection {
+ collection_space_id: active_space,
+ thread_id: thread_id.clone(),
+ },
+ true,
+ );
+ items.push(remove_item);
+ if let Some(origin_space) = crate::workspace_threads::thread_space_id(&thread_id) {
+ let origin_item = self.context_menu_application_item_with_icon(
+ crate::i18n::tr("menu-go-to-origin-space"),
+ ContextMenuIcon::ExternalLink,
+ crate::termwindow::ContextMenuApplicationAction::ActivateWorkspaceThread {
+ space_id: origin_space,
+ thread_id: thread_id.clone(),
+ },
+ true,
+ );
+ items.push(origin_item);
+ }
+ } else {
+ let collections = crate::workspace_threads::collection_spaces();
+ if collections.is_empty() {
+ let add_item = self.context_menu_application_item_with_icon(
+ crate::i18n::tr("menu-add-to-collection"),
+ ContextMenuIcon::Pin,
+ crate::termwindow::ContextMenuApplicationAction::AddThreadToCollection {
+ collection_space_id: None,
+ thread_id: thread_id.clone(),
+ },
+ true,
+ );
+ items.push(add_item);
+ } else {
+ for (space_id, name) in collections {
+ let already =
+ crate::workspace_threads::thread_ref_exists(&space_id, &thread_id);
+ let add_item = self.context_menu_application_item_with_icon(
+ tr_with_name("menu-add-to-collection-named", &name),
+ ContextMenuIcon::Pin,
+ crate::termwindow::ContextMenuApplicationAction::AddThreadToCollection {
+ collection_space_id: Some(space_id),
+ thread_id: thread_id.clone(),
+ },
+ !already,
+ );
+ items.push(add_item);
+ }
+ }
+ }
items
}
@@ -5473,13 +5583,27 @@ impl super::TermWindow {
self.snapshot_active_workspace_thread_layout();
let use_mosh = spec.use_mosh;
+ // A collection Space owns no projects, so the SSH-hosts view (whose
+ // footer button is reachable in a collection window too) must not
+ // create the host project there — it would be permanently invisible.
+ // The host lands in the default Space and the collection gets a
+ // reference, which is exactly how a collection displays anything.
+ let host_space_id =
+ if crate::workspace_threads::is_collection_space(&self.active_space_id) {
+ crate::workspace_threads::default_space_id()
+ } else {
+ self.active_space_id.clone()
+ };
let thread_id = crate::workspace_threads::create_disconnected_remote_host_thread(
- &self.active_space_id,
+ &host_space_id,
&host_id,
&spec.label,
crate::ssh_hosts::host_project_path(&spec),
spec.default_workspace.clone(),
);
+ if host_space_id != self.active_space_id {
+ crate::workspace_threads::add_thread_ref(&self.active_space_id, &thread_id);
+ }
if !self.open_remote_workspace_thread_without_connecting(&thread_id, context) {
context.invalidate();
return false;
@@ -5707,8 +5831,11 @@ impl super::TermWindow {
self.kill_remote_connect_workspace(&workspace_name);
} else if reveal_now {
let live_workspaces = Mux::get().iter_workspaces();
- let _ =
- crate::workspace_threads::activate_thread_record(&thread_id, &live_workspaces);
+ let _ = crate::workspace_threads::activate_thread_record(
+ &thread_id,
+ &live_workspaces,
+ true,
+ );
self.adopt_workspace_in_this_window(&workspace_name);
cleanup_orphaned_mux_window(orphan_candidate_window_id);
kill_workspace_windows(&workspaces_to_kill_after_adopt, Some(&workspace_name));
@@ -5752,9 +5879,14 @@ impl super::TermWindow {
orphan_candidate_window_id: Option<MuxWindowId>,
workspaces_to_kill_after_adopt: Vec<String>,
) {
- if crate::workspace_threads::thread_space_id(&thread_id).as_deref()
- != Some(self.active_space_id.as_str())
- {
+ let thread_home_space = crate::workspace_threads::thread_space_id(&thread_id);
+ let in_this_space = thread_home_space.as_deref() == Some(self.active_space_id.as_str());
+ // A collection Space window may activate any thread it references:
+ // the reference opens in place while the thread keeps belonging to
+ // its origin Space.
+ let via_collection_ref = !in_this_space
+ && crate::workspace_threads::thread_ref_exists(&self.active_space_id, &thread_id);
+ if !in_this_space && !via_collection_ref {
context.invalidate();
return;
}
@@ -5778,13 +5910,44 @@ impl super::TermWindow {
}
}
+ // Two GUI windows sharing one mux window fight over geometry (both
+ // resize the same tabs). When another window is already showing the
+ // target workspace — a collection window that opened it in place, the
+ // origin-Space window while a collection shows it, or a connect
+ // window displaying a workspace of a Space it did not claim — hand
+ // the click to that window instead of adopting. Checked before any
+ // record mutation so a handed-off click leaves no trace here.
+ if let Some(plan) =
+ crate::workspace_threads::activation_plan_for_thread(&thread_id, &live_workspaces)
+ {
+ if !plan.needs_materialize {
+ let target = mux
+ .iter_windows_in_workspace(&plan.workspace_name)
+ .into_iter()
+ .next();
+ if let Some(target) = target {
+ if target != self.mux_window_id {
+ if let Some(other) =
+ crate::frontend::front_end().gui_window_for_mux_window(target)
+ {
+ other.window.focus();
+ context.invalidate();
+ return;
+ }
+ }
+ }
+ }
+ }
+
self.snapshot_active_workspace_thread_layout();
self.workspace_sidebar_pending_thread_selection = None;
self.set_content_view_active(false);
- let Some(plan) =
- crate::workspace_threads::activate_thread_record(&thread_id, &live_workspaces)
- else {
+ let Some(plan) = crate::workspace_threads::activate_thread_record(
+ &thread_id,
+ &live_workspaces,
+ !via_collection_ref,
+ ) else {
context.invalidate();
return;
};
@@ -5802,9 +5965,18 @@ impl super::TermWindow {
// In a mux-client-domain Space every thread targets the remote
// server: panes spawn into the client domain, never a local shell.
- // That requires the domain to be attached first.
+ // That requires the domain to be attached first. For a collection
+ // reference the thread's own Space decides the domain — the
+ // collection Space itself is local and has none.
+ let domain_space_id = if via_collection_ref {
+ thread_home_space
+ .clone()
+ .unwrap_or_else(|| self.active_space_id.clone())
+ } else {
+ self.active_space_id.clone()
+ };
let space_client_domain =
- crate::workspace_threads::client_domain_for_space(&self.active_space_id);
+ crate::workspace_threads::client_domain_for_space(&domain_space_id);
if let Some(domain_name) = space_client_domain.as_deref() {
let attached = mux
.get_domain_by_name(domain_name)
diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs
index 5a635574..0378f740 100644
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -1689,21 +1689,36 @@ impl super::TermWindow {
let Some(window) = mux.get_window(self.mux_window_id) else {
return;
};
+ let space_id = self.space_id_for_layout_snapshot(window.get_workspace());
crate::workspace_threads::snapshot_active_space_thread_layout_with_font_scales(
- &self.active_space_id,
+ &space_id,
window.get_workspace(),
self.mux_window_id,
|pane_id| self.persisted_font_scale_for_pane(pane_id),
);
}
+ /// The Space a layout snapshot should be recorded under. A collection
+ /// Space window displays workspaces that belong to other Spaces, and the
+ /// snapshot store refuses a Space/workspace mismatch — so resolve the
+ /// workspace's own Space there; everywhere else the window's Space is it.
+ fn space_id_for_layout_snapshot(&self, workspace: &str) -> String {
+ if crate::workspace_threads::is_collection_space(&self.active_space_id) {
+ if let Some(space_id) = crate::workspace_threads::space_id_for_workspace(workspace) {
+ return space_id;
+ }
+ }
+ self.active_space_id.clone()
+ }
+
fn persist_workspace_pane_font_scales(&self) {
let mux = Mux::get();
let Some(window) = mux.get_window(self.mux_window_id) else {
return;
};
+ let space_id = self.space_id_for_layout_snapshot(window.get_workspace());
crate::workspace_threads::snapshot_active_space_thread_layout_with_font_scales(
- &self.active_space_id,
+ &space_id,
window.get_workspace(),
self.mux_window_id,
|pane_id| self.persisted_font_scale_for_pane(pane_id),
diff --git a/wezterm-gui/src/termwindow/ui/context_menu.rs b/wezterm-gui/src/termwindow/ui/context_menu.rs
index d9883ca8..2635f1c6 100644
--- a/wezterm-gui/src/termwindow/ui/context_menu.rs
+++ b/wezterm-gui/src/termwindow/ui/context_menu.rs
@@ -227,6 +227,33 @@ impl crate::TermWindow {
) => {
self.toggle_workspace_sidebar_status_filter(status);
}
+ crate::termwindow::ContextMenuApplicationAction::AddThreadToCollection {
+ collection_space_id,
+ thread_id,
+ } => {
+ let collection_space_id = collection_space_id
+ .unwrap_or_else(|| crate::workspace_threads::create_collection_space(None));
+ if crate::workspace_threads::add_thread_ref(&collection_space_id, &thread_id) {
+ self.invalidate_window();
+ }
+ }
+ crate::termwindow::ContextMenuApplicationAction::RemoveThreadFromCollection {
+ collection_space_id,
+ thread_id,
+ } => {
+ if crate::workspace_threads::remove_thread_ref(&collection_space_id, &thread_id) {
+ self.invalidate_window();
+ }
+ }
+ crate::termwindow::ContextMenuApplicationAction::CreateCollectionSpace => {
+ let Some(window) = self.window.clone() else {
+ return;
+ };
+ let space_id = crate::workspace_threads::create_collection_space(None);
+ self.switch_space(space_id.clone(), &window);
+ self.prompt_rename_space(space_id);
+ window.invalidate();
+ }
crate::termwindow::ContextMenuApplicationAction::DownloadRemoteFile {
path,
origin,
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 66305d46..72de4499 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -381,6 +381,11 @@ impl crate::TermWindow {
&self,
mut view: workspace_threads::WorkspaceThreadsView,
) -> workspace_threads::WorkspaceThreadsView {
+ // A collection is a hand-curated list; hiding rows by work status
+ // would blank it with no explanation.
+ if crate::workspace_threads::is_collection_space(self.workspace_sidebar_space_id()) {
+ return view;
+ }
let hidden = crate::native_settings::workspace_sidebar_hidden_statuses()
.iter()
.filter_map(|key| workspace_threads::WorkspaceThreadWorkStatus::from_settings_key(key))
@@ -1547,11 +1552,18 @@ impl crate::TermWindow {
label_icon_size,
muted_fg,
)?;
+ let section_label = if crate::workspace_threads::is_collection_space(
+ self.workspace_sidebar_space_id(),
+ ) {
+ crate::i18n::tr("sidebar-collection-threads")
+ } else {
+ crate::i18n::tr("sidebar-pinned")
+ };
self.paint_sidebar_text(
layers,
&ui_font,
ui_metrics,
- &crate::i18n::tr("sidebar-pinned"),
+ &section_label,
label_text_x,
label_y + ((session_row_height.saturating_sub(ui_cell_height)) / 2),
item_x
@@ -1666,20 +1678,40 @@ impl crate::TermWindow {
)?;
if is_hovered && !is_renaming_session {
- for (x, item_type, icon, _context_name) in [
+ // In a collection Space the pin toggle would mutate
+ // the origin thread; only removal makes sense there.
+ let in_collection = crate::workspace_threads::is_collection_space(
+ self.workspace_sidebar_space_id(),
+ );
+ // An X, not a trash can: the affordance removes the
+ // reference, the origin thread keeps running.
+ let mut affordances = vec![if in_collection {
(
- pin_x,
- UIItemType::WorkspaceThreadPin(session.id.clone()),
- SvgIcon::PinOff,
- "sidebar unpin pinned thread button",
- ),
+ delete_x,
+ UIItemType::WorkspaceThreadDelete(session.id.clone()),
+ SvgIcon::X,
+ "sidebar remove collection reference button",
+ )
+ } else {
(
delete_x,
UIItemType::WorkspaceThreadDelete(session.id.clone()),
SvgIcon::Trash2,
"sidebar delete pinned thread button",
- ),
- ] {
+ )
+ }];
+ if !in_collection {
+ affordances.insert(
+ 0,
+ (
+ pin_x,
+ UIItemType::WorkspaceThreadPin(session.id.clone()),
+ SvgIcon::PinOff,
+ "sidebar unpin pinned thread button",
+ ),
+ );
+ }
+ for (x, item_type, icon, _context_name) in affordances {
let hovered =
self.is_pointer_over_ui_rect(x, action_y, action_size, action_size);
self.ui_items.push(UIItem {
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 45d851f4..391c7ed4 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -66,6 +66,20 @@ pub struct Space {
/// layout locally (the remote mux server owns the layout truth).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub client_domain: Option<String>,
+ /// A collection Space holds `thread_refs` instead of projects: references
+ /// to Threads that keep living in their own Spaces, possibly on other
+ /// machines. Purely local — no server ever learns about it, which is what
+ /// lets one Space mix threads from several mux domains without any
+ /// protocol change. Never claimed by startup windows, never auto-seeded
+ /// with a Home project.
+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]
+ pub is_collection: bool,
+ /// Thread ids referenced by a collection Space, in display order. Only
+ /// the id is stored; the origin project/Space is resolved live, so a
+ /// reference whose thread has vanished simply resolves to nothing and is
+ /// pruned on the next load.
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub thread_refs: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
@@ -176,6 +190,29 @@ pub struct WorkspaceThreadView {
pub work_status: WorkspaceThreadWorkStatus,
}
+/// One row of a collection Space: a reference to a Thread that lives in some
+/// other Space, resolved live against the store. A reference whose thread has
+/// vanished simply produces no view.
+#[derive(Debug, Clone)]
+// The origin fields are asserted by the store tests and reserved for row
+// painting polish (offline dimming, origin tooltips); the bin target does
+// not read them yet.
+#[allow(dead_code)]
+pub struct ThreadRefView {
+ pub thread: WorkspaceThreadView,
+ pub origin_space_id: SpaceId,
+ pub origin_space_name: String,
+ /// Short machine tag for the row: the origin Space's mux domain name
+ /// (which is the user's host label when one exists) or "Local".
+ pub machine_label: String,
+ /// False when the origin Space's mux domain is currently detached; the
+ /// sidebar dims such rows.
+ pub origin_domain_attached: bool,
+ /// The workspace this reference resolves to; the paint side compares it
+ /// against the window's current workspace to mark the active row.
+ pub workspace_name: String,
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WorkspaceThreadWorkStatus {
Idle,
@@ -915,6 +952,113 @@ pub fn create_space(name: Option<String>) -> SpaceId {
id
}
+/// Create a collection Space: a purely local Space that holds references to
+/// Threads living in other Spaces (possibly other machines). No server ever
+/// learns about it.
+pub fn create_collection_space(name: Option<String>) -> SpaceId {
+ let mut store = THREAD_STORE.lock();
+ store.normalize_after_load();
+ let name = name.unwrap_or_else(|| next_collection_space_name(&store.spaces));
+ let id = store.create_space_record(name);
+ if let Some(space) = store.spaces.iter_mut().find(|space| space.id == id) {
+ space.is_collection = true;
+ }
+ // last_active_space_id is left alone on purpose: the menu flow switches
+ // to the new Space explicitly (which records it), while "Add to
+ // Collection" creates one in the background without visiting it.
+ persist_locked(&store);
+ id
+}
+
+/// "Collection", "Collection 2", …: several collections would otherwise be
+/// indistinguishable in the "Add to …" menu.
+fn next_collection_space_name(spaces: &[Space]) -> String {
+ let mut index = 1;
+ loop {
+ let name = if index == 1 {
+ "Collection".to_string()
+ } else {
+ format!("Collection {index}")
+ };
+ if !spaces.iter().any(|space| space.name == name) {
+ return name;
+ }
+ index += 1;
+ }
+}
+
+pub fn is_collection_space(space_id: &str) -> bool {
+ THREAD_STORE.lock().is_collection_space(space_id)
+}
+
+/// (id, name) of every collection Space, for menu listings.
+pub fn collection_spaces() -> Vec<(SpaceId, String)> {
+ THREAD_STORE
+ .lock()
+ .spaces
+ .iter()
+ .filter(|space| space.is_collection)
+ .map(|space| (space.id.clone(), space.name.clone()))
+ .collect()
+}
+
+pub fn add_thread_ref(collection_space_id: &str, thread_id: &str) -> bool {
+ let mut store = THREAD_STORE.lock();
+ store.normalize_after_load();
+ let added = store.add_thread_ref(collection_space_id, thread_id);
+ if added {
+ persist_locked(&store);
+ }
+ added
+}
+
+pub fn remove_thread_ref(collection_space_id: &str, thread_id: &str) -> bool {
+ let mut store = THREAD_STORE.lock();
+ store.normalize_after_load();
+ let removed = store.remove_thread_ref(collection_space_id, thread_id);
+ if removed {
+ persist_locked(&store);
+ }
+ removed
+}
+
+pub fn move_thread_ref_before(
+ collection_space_id: &str,
+ thread_id: &str,
+ before: Option<&str>,
+) -> bool {
+ let mut store = THREAD_STORE.lock();
+ store.normalize_after_load();
+ let moved = store.move_thread_ref_before(collection_space_id, thread_id, before);
+ if moved {
+ persist_locked(&store);
+ }
+ moved
+}
+
+/// The reference list of a collection Space, in display order.
+pub fn collection_thread_refs(collection_space_id: &str) -> Vec<String> {
+ THREAD_STORE
+ .lock()
+ .spaces
+ .iter()
+ .find(|space| space.id == collection_space_id && space.is_collection)
+ .map(|space| space.thread_refs.clone())
+ .unwrap_or_default()
+}
+
+pub fn thread_ref_exists(collection_space_id: &str, thread_id: &str) -> bool {
+ THREAD_STORE
+ .lock()
+ .spaces
+ .iter()
+ .any(|space| {
+ space.id == collection_space_id
+ && space.is_collection
+ && space.thread_refs.iter().any(|id| id == thread_id)
+ })
+}
+
/// Add another Space to a remote server.
///
/// The Space lives on the server like any other, so it is created locally with
@@ -1070,10 +1214,12 @@ fn delete_space_for_window_local(
.iter()
.find(|space| space.is_default && !occupied_by_other.contains(&space.id))
.or_else(|| {
+ // A collection cannot rehome a window: it has no thread for
+ // the window to adopt.
store
.spaces
.iter()
- .find(|space| !occupied_by_other.contains(&space.id))
+ .find(|space| !occupied_by_other.contains(&space.id) && !space.is_collection)
})
.map(|space| space.id.clone())
.unwrap_or_else(|| {
@@ -1232,10 +1378,12 @@ pub async fn delete_space_for_window(
.iter()
.find(|space| space.is_default && !occupied_by_other.contains(&space.id))
.or_else(|| {
+ // A collection cannot rehome a window: it has no thread for
+ // the window to adopt.
store
.spaces
.iter()
- .find(|space| !occupied_by_other.contains(&space.id))
+ .find(|space| !occupied_by_other.contains(&space.id) && !space.is_collection)
})
.map(|space| space.id.clone())
.unwrap_or_else(|| {
@@ -1257,6 +1405,14 @@ pub fn ensure_active_thread_for_space(space_id: &str) -> Option<WorkspaceThreadI
if !store.has_space(space_id) {
return None;
}
+ // A collection Space owns no projects and must not be seeded with a Home
+ // project; its rows are references into other Spaces.
+ if store.is_collection_space(space_id) {
+ if changed {
+ persist_locked(&store);
+ }
+ return None;
+ }
let project_id = store
.active_project_id_for_space(space_id)
.filter(|project_id| {
@@ -1301,6 +1457,14 @@ pub fn thread_to_restore_for_space(space_id: &str) -> Option<WorkspaceThreadId>
thread_id
}
+/// The Space that owns `workspace`, resolved through the thread binding.
+/// Used by collection-Space windows, whose own space id is not the one layout
+/// snapshots for the displayed workspace should land under.
+pub fn space_id_for_workspace(workspace: &str) -> Option<SpaceId> {
+ let store = THREAD_STORE.lock();
+ store.workspace_space_id(workspace)
+}
+
pub fn workspace_has_thread_binding(workspace: &str) -> bool {
let mut store = THREAD_STORE.lock();
if store.normalize_after_load() {
@@ -1355,6 +1519,26 @@ pub fn view_for_current_project(
if store.normalize_after_load() {
persist_locked(&store);
}
+ if store.is_collection_space(space_id) {
+ // A collection Space renders its references where the pinned section
+ // normally goes and owns no projects, so every existing geometry and
+ // row-painting path works on this view unchanged. The machine tag
+ // rides in the display name; the sidebar has no other per-row slot
+ // without new painting code.
+ let pinned_threads = store
+ .view_for_collection_space(space_id, live_workspaces, Some(active_workspace))
+ .into_iter()
+ .map(|r| {
+ let mut thread = r.thread;
+ thread.name = format!("{} · {}", thread.name, r.machine_label);
+ thread
+ })
+ .collect();
+ return WorkspaceThreadsView {
+ pinned_threads,
+ projects: Vec::new(),
+ };
+ }
if let Some(project_id) = store
.project_id_for_workspace(space_id, active_workspace)
.or_else(|| store.active_project_id_for_space(space_id))
@@ -1497,12 +1681,16 @@ pub fn create_disconnected_remote_host_thread(
thread_id
}
+/// `repoint_space_active` is false when the activation comes through a
+/// collection reference: the origin Space's active project/thread pointers
+/// stay untouched so its own window keeps snapshotting the thread it shows.
pub fn activate_thread_record(
thread_id: &str,
live_workspaces: &[String],
+ repoint_space_active: bool,
) -> Option<ActivationPlan> {
let mut store = THREAD_STORE.lock();
- let plan = store.activate_thread_record(thread_id, live_workspaces);
+ let plan = store.activate_thread_record(thread_id, live_workspaces, repoint_space_active);
schedule_workspace_thread_store_persist();
if plan.is_some() {
submit_thread_state(&store, thread_id);
@@ -3276,6 +3464,8 @@ impl WorkspaceThreadStore {
note_vault: None,
is_default: true,
client_domain: None,
+ is_collection: false,
+ thread_refs: Vec::new(),
});
changed = true;
}
@@ -3351,6 +3541,27 @@ impl WorkspaceThreadStore {
}
changed |= self.repair_cross_space_local_workspace_bindings();
changed |= self.ensure_unique_thread_names();
+ changed |= self.prune_dangling_thread_refs();
+ changed
+ }
+
+ /// Drop collection references whose thread no longer exists anywhere.
+ /// Server-side deletions arrive silently through ingest, so this runs as
+ /// part of normalize (every store entry point) rather than only at the
+ /// local delete sites; between runs the view builder simply skips
+ /// unresolvable refs.
+ fn prune_dangling_thread_refs(&mut self) -> bool {
+ let known: std::collections::HashSet<&str> = self
+ .projects
+ .iter()
+ .flat_map(|project| project.threads.iter().map(|thread| thread.id.as_str()))
+ .collect();
+ let mut changed = false;
+ for space in self.spaces.iter_mut().filter(|space| space.is_collection) {
+ let before = space.thread_refs.len();
+ space.thread_refs.retain(|id| known.contains(id.as_str()));
+ changed |= space.thread_refs.len() != before;
+ }
changed
}
@@ -3375,6 +3586,8 @@ impl WorkspaceThreadStore {
note_vault: None,
is_default: false,
client_domain,
+ is_collection: false,
+ thread_refs: Vec::new(),
});
id
}
@@ -3385,18 +3598,25 @@ impl WorkspaceThreadStore {
) -> SpaceId {
// Mux-domain Spaces belong to `thinkterm connect`; startup and Dock
// "New Window" must never claim them (they would materialize a local
- // shell into a remote-owned workspace).
+ // shell into a remote-owned workspace). Collection Spaces hold thread
+ // references rather than projects, so a startup window claiming one
+ // would immediately seed it with a Home project it must not have.
self.last_active_space_id
.clone()
.filter(|space_id| {
self.has_space(space_id)
&& !occupied.contains(space_id)
&& !self.is_client_domain_space(space_id)
+ && !self.is_collection_space(space_id)
})
.or_else(|| {
self.spaces
.iter()
- .find(|space| !occupied.contains(&space.id) && space.client_domain.is_none())
+ .find(|space| {
+ !occupied.contains(&space.id)
+ && space.client_domain.is_none()
+ && !space.is_collection
+ })
.map(|space| space.id.clone())
})
.unwrap_or_else(|| {
@@ -3456,6 +3676,146 @@ impl WorkspaceThreadStore {
.any(|space| space.id == space_id && space.client_domain.is_some())
}
+ fn is_collection_space(&self, space_id: &str) -> bool {
+ self.spaces
+ .iter()
+ .any(|space| space.id == space_id && space.is_collection)
+ }
+
+ fn add_thread_ref(&mut self, collection_space_id: &str, thread_id: &str) -> bool {
+ let exists = self
+ .projects
+ .iter()
+ .any(|project| project.threads.iter().any(|thread| thread.id == thread_id));
+ if !exists {
+ return false;
+ }
+ let Some(space) = self
+ .spaces
+ .iter_mut()
+ .find(|space| space.id == collection_space_id && space.is_collection)
+ else {
+ return false;
+ };
+ if space.thread_refs.iter().any(|id| id == thread_id) {
+ return false;
+ }
+ space.thread_refs.push(thread_id.to_string());
+ true
+ }
+
+ fn remove_thread_ref(&mut self, collection_space_id: &str, thread_id: &str) -> bool {
+ let Some(space) = self
+ .spaces
+ .iter_mut()
+ .find(|space| space.id == collection_space_id && space.is_collection)
+ else {
+ return false;
+ };
+ let before = space.thread_refs.len();
+ space.thread_refs.retain(|id| id != thread_id);
+ space.thread_refs.len() != before
+ }
+
+ /// Reorder a reference before another (or to the end with `None`).
+ /// Purely local: reference order never travels to any server.
+ fn move_thread_ref_before(
+ &mut self,
+ collection_space_id: &str,
+ thread_id: &str,
+ before: Option<&str>,
+ ) -> bool {
+ let Some(space) = self
+ .spaces
+ .iter_mut()
+ .find(|space| space.id == collection_space_id && space.is_collection)
+ else {
+ return false;
+ };
+ let Some(from) = space.thread_refs.iter().position(|id| id == thread_id) else {
+ return false;
+ };
+ // Mirror move_thread_before's guards: a drop on the row itself or on
+ // an anchor that has meanwhile vanished cancels the drag instead of
+ // teleporting the reference to the end of the list.
+ let to = match before {
+ Some(anchor) => {
+ if anchor == thread_id {
+ return false;
+ }
+ let Some(index) = space.thread_refs.iter().position(|id| id == anchor) else {
+ return false;
+ };
+ index
+ }
+ None => space.thread_refs.len(),
+ };
+ if to == from || to == from + 1 {
+ return false;
+ }
+ let moved = space.thread_refs.remove(from);
+ let to = if to > from { to - 1 } else { to };
+ space.thread_refs.insert(to, moved);
+ true
+ }
+
+ fn view_for_collection_space(
+ &self,
+ space_id: &str,
+ live_workspaces: &[String],
+ active_workspace: Option<&str>,
+ ) -> Vec<ThreadRefView> {
+ let Some(space) = self
+ .spaces
+ .iter()
+ .find(|space| space.id == space_id && space.is_collection)
+ else {
+ return Vec::new();
+ };
+ space
+ .thread_refs
+ .iter()
+ .filter_map(|thread_id| {
+ let project = self
+ .projects
+ .iter()
+ .find(|project| project.threads.iter().any(|t| &t.id == thread_id))?;
+ let origin = self.spaces.iter().find(|s| s.id == project.space_id)?;
+ let session = project.threads.iter().find(|t| &t.id == thread_id)?;
+ let workspace_name = session
+ .materialized_workspace_name
+ .clone()
+ .unwrap_or_else(|| workspace_name_for_thread(&project.id, &session.id));
+ let thread = WorkspaceThreadView {
+ id: session.id.clone(),
+ name: session.name.clone(),
+ is_active: active_workspace == Some(workspace_name.as_str()),
+ is_materialized: live_workspaces.iter().any(|live| live == &workspace_name),
+ is_pinned: session.is_pinned,
+ is_unread: session.is_unread,
+ work_status: session.work_status(),
+ };
+ let machine_label = origin
+ .client_domain
+ .clone()
+ .unwrap_or_else(|| "Local".to_string());
+ let origin_domain_attached = origin
+ .client_domain
+ .as_deref()
+ .map(remote_tree_domain_is_attached)
+ .unwrap_or(true);
+ Some(ThreadRefView {
+ thread,
+ origin_space_id: origin.id.clone(),
+ origin_space_name: origin.name.clone(),
+ machine_label,
+ origin_domain_attached,
+ workspace_name,
+ })
+ })
+ .collect()
+ }
+
fn rename_space(&mut self, space_id: &str, name: String) -> bool {
let name = name.trim();
if name.is_empty() {
@@ -3725,6 +4085,13 @@ impl WorkspaceThreadStore {
fn sync_current_project(&mut self, space_id: &str, active_workspace: &str) -> bool {
let mut changed = self.normalize_after_load();
+ // A collection Space owns no projects: the workspace on display
+ // belongs to a reference's origin Space, and falling through to
+ // ensure_current_project would seed the collection with a Home
+ // project the views never show.
+ if self.is_collection_space(space_id) {
+ return changed;
+ }
if self.workspace_belongs_to_other_space(space_id, active_workspace) {
return changed;
}
@@ -4092,6 +4459,7 @@ impl WorkspaceThreadStore {
&mut self,
thread_id: &str,
live_workspaces: &[String],
+ repoint_space_active: bool,
) -> Option<ActivationPlan> {
let plan = self.activation_plan_for_thread(thread_id, live_workspaces)?;
let project = self
@@ -4106,11 +4474,17 @@ impl WorkspaceThreadStore {
session.last_active_at = now_ts();
session.is_unread = false;
session.work_finished_unseen = false;
- project.active_thread_id = Some(plan.thread_id.clone());
- let space_id = project.space_id.clone();
- let active_project_id = project.id.clone();
- let _ = project;
- self.set_active_project_for_space(&space_id, active_project_id);
+ // A collection window passes false: opening a reference in place is
+ // a collection-local affair and must not change what the origin
+ // Space's own window considers active — that window keys its layout
+ // snapshots off these pointers.
+ if repoint_space_active {
+ project.active_thread_id = Some(plan.thread_id.clone());
+ let space_id = project.space_id.clone();
+ let active_project_id = project.id.clone();
+ let _ = project;
+ self.set_active_project_for_space(&space_id, active_project_id);
+ }
Some(plan)
}
@@ -4571,6 +4945,8 @@ impl WorkspaceThreadStore {
note_vault,
is_default: false,
client_domain: Some(domain_name.to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
}
})
.collect();
@@ -6516,6 +6892,190 @@ mod tests {
store
}
+ /// A store with one local project of two threads plus one collection
+ /// Space, for the reference tests.
+ fn store_with_collection() -> (WorkspaceThreadStore, String, String, String) {
+ let mut store = test_store();
+ let mut project = default_project_for_space(DEFAULT_SPACE_ID);
+ let t1 = WorkspaceThread::new(project.id.clone(), "alpha".to_string(), None);
+ let t2 = WorkspaceThread::new(project.id.clone(), "beta".to_string(), None);
+ let (t1_id, t2_id) = (t1.id.clone(), t2.id.clone());
+ project.threads.push(t1);
+ project.threads.push(t2);
+ store.projects.push(project);
+ let coll_id = store.create_space_record("Collection".to_string());
+ store
+ .spaces
+ .iter_mut()
+ .find(|space| space.id == coll_id)
+ .unwrap()
+ .is_collection = true;
+ (store, coll_id, t1_id, t2_id)
+ }
+
+ #[test]
+ fn collection_space_is_never_claimed_by_startup_windows() {
+ let (mut store, coll_id, _, _) = store_with_collection();
+ // Simulate the collection being the last thing the user looked at.
+ store.last_active_space_id = Some(coll_id.clone());
+ let mut occupied = std::collections::HashSet::new();
+ occupied.insert(DEFAULT_SPACE_ID.to_string());
+ let claimed = store.claim_available_space_id(&occupied);
+ assert_ne!(claimed, coll_id, "startup window must not claim a collection Space");
+ }
+
+ #[test]
+ fn collection_refs_add_remove_reorder_dedup() {
+ let (mut store, coll, t1, t2) = store_with_collection();
+ assert!(store.add_thread_ref(&coll, &t1));
+ assert!(!store.add_thread_ref(&coll, &t1), "duplicate ref must be refused");
+ assert!(store.add_thread_ref(&coll, &t2));
+ assert!(!store.add_thread_ref(&coll, "thread-nonexistent"));
+
+ let refs = |store: &WorkspaceThreadStore| {
+ store
+ .spaces
+ .iter()
+ .find(|s| s.id == coll)
+ .unwrap()
+ .thread_refs
+ .clone()
+ };
+ assert_eq!(refs(&store), vec![t1.clone(), t2.clone()]);
+
+ assert!(store.move_thread_ref_before(&coll, &t2, Some(&t1)));
+ assert_eq!(refs(&store), vec![t2.clone(), t1.clone()]);
+ assert!(store.move_thread_ref_before(&coll, &t2, None));
+ assert_eq!(refs(&store), vec![t1.clone(), t2.clone()]);
+
+ assert!(store.remove_thread_ref(&coll, &t1));
+ assert!(!store.remove_thread_ref(&coll, &t1));
+ assert_eq!(refs(&store), vec![t2.clone()]);
+ }
+
+ #[test]
+ fn dangling_refs_are_pruned_on_normalize() {
+ let (mut store, coll, t1, t2) = store_with_collection();
+ assert!(store.add_thread_ref(&coll, &t1));
+ assert!(store.add_thread_ref(&coll, &t2));
+ // The thread disappears (as a server-side deletion arriving via
+ // ingest would make it).
+ store.projects[0].threads.retain(|thread| thread.id != t1);
+ assert!(store.normalize_after_load());
+ let space = store.spaces.iter().find(|s| s.id == coll).unwrap();
+ assert_eq!(space.thread_refs, vec![t2]);
+ }
+
+ #[test]
+ fn collection_view_resolves_origin_and_skips_dangling() {
+ let (mut store, coll, t1, _) = store_with_collection();
+ assert!(store.add_thread_ref(&coll, &t1));
+ // A dangling ref sneaks in (e.g. deleted on the server between
+ // normalize runs): the view must simply skip it.
+ store
+ .spaces
+ .iter_mut()
+ .find(|s| s.id == coll)
+ .unwrap()
+ .thread_refs
+ .push("thread-gone".to_string());
+
+ let views = store.view_for_collection_space(&coll, &[], None);
+ assert_eq!(views.len(), 1);
+ let view = &views[0];
+ assert_eq!(view.thread.id, t1);
+ assert_eq!(view.origin_space_id, DEFAULT_SPACE_ID);
+ assert_eq!(view.machine_label, "Local");
+ assert!(view.origin_domain_attached);
+ assert!(!view.thread.is_active);
+
+ // Active-row detection keys off the resolved workspace name.
+ let active = store.view_for_collection_space(&coll, &[], Some(view.workspace_name.as_str()));
+ assert!(active[0].thread.is_active);
+ }
+
+ #[test]
+ fn ingest_leaves_collection_spaces_alone() {
+ let mut store = remote_test_store("syd");
+ assert!(store.ingest_remote_tree("syd", &sample_tree()));
+ let coll_id = store.create_space_record("Collection".to_string());
+ store
+ .spaces
+ .iter_mut()
+ .find(|space| space.id == coll_id)
+ .unwrap()
+ .is_collection = true;
+ // Reference a remote thread from the ingested tree.
+ let remote_thread_id = store.projects.iter().find(|p| p.id == "rp1").unwrap().threads[0]
+ .id
+ .clone();
+ assert!(store.add_thread_ref(&coll_id, &remote_thread_id));
+
+ // Another push from the server must not disturb the local collection.
+ store.ingest_remote_tree("syd", &sample_tree());
+ let space = store.spaces.iter().find(|s| s.id == coll_id).unwrap();
+ assert!(space.is_collection);
+ assert_eq!(space.thread_refs, vec![remote_thread_id]);
+ }
+
+ #[test]
+ fn reorder_guards_cancel_self_and_stale_anchors() {
+ let (mut store, coll, t1, t2) = store_with_collection();
+ assert!(store.add_thread_ref(&coll, &t1));
+ assert!(store.add_thread_ref(&coll, &t2));
+ // Dropping a row onto itself must not teleport it to the end.
+ assert!(!store.move_thread_ref_before(&coll, &t1, Some(&t1)));
+ // An anchor that vanished mid-drag cancels instead of moving to end.
+ assert!(!store.move_thread_ref_before(&coll, &t1, Some("thread-gone")));
+ // Dropping right before the next sibling is a positional no-op.
+ assert!(!store.move_thread_ref_before(&coll, &t1, Some(&t2)));
+ let space = store.spaces.iter().find(|s| s.id == coll).unwrap();
+ assert_eq!(space.thread_refs, vec![t1, t2]);
+ }
+
+ #[test]
+ fn sync_current_project_never_seeds_collections() {
+ let (mut store, coll, _, _) = store_with_collection();
+ // An unbound workspace (e.g. its thread binding was pruned by a
+ // remote delete) used to fall through to ensure_current_project.
+ store.sync_current_project(&coll, "some-unbound-workspace");
+ assert!(
+ store.projects.iter().all(|project| project.space_id != coll),
+ "a collection Space must never acquire a project"
+ );
+ }
+
+ #[test]
+ fn collection_names_stay_distinguishable() {
+ let (mut store, _, _, _) = store_with_collection();
+ assert_eq!(next_collection_space_name(&store.spaces), "Collection 2");
+ let id = store.create_space_record("Collection 2".to_string());
+ store
+ .spaces
+ .iter_mut()
+ .find(|space| space.id == id)
+ .unwrap()
+ .is_collection = true;
+ assert_eq!(next_collection_space_name(&store.spaces), "Collection 3");
+ }
+
+ #[test]
+ fn collection_activation_leaves_origin_pointers_alone() {
+ let (mut store, _coll, t1, t2) = store_with_collection();
+ store.activate_thread_record(&t2, &[], true).unwrap();
+ assert_eq!(
+ store.projects[0].active_thread_id.as_deref(),
+ Some(t2.as_str())
+ );
+ // A collection window activating a reference passes false: what the
+ // origin Space considers active must not change under its window.
+ store.activate_thread_record(&t1, &[], false).unwrap();
+ assert_eq!(
+ store.projects[0].active_thread_id.as_deref(),
+ Some(t2.as_str())
+ );
+ }
+
fn space_view(id: &str, is_remote: bool, is_occupied_by_other_window: bool) -> SpaceView {
SpaceView {
id: id.to_string(),
@@ -7322,7 +7882,7 @@ mod tests {
.is_none());
assert_eq!(store.thread_to_restore_for_space(&space_id), (None, false));
- let plan = store.activate_thread_record(&thread_id, &[]).unwrap();
+ let plan = store.activate_thread_record(&thread_id, &[], true).unwrap();
assert!(plan.needs_materialize);
assert_eq!(
store.projects[0].active_thread_id.as_deref(),
@@ -7380,7 +7940,7 @@ mod tests {
assert!(!state.is_live);
let plan = store
- .activate_thread_record(&thread_id, &[])
+ .activate_thread_record(&thread_id, &[], true)
.expect("activation plan");
assert_eq!(plan.workspace_name, expected_workspace);
}
@@ -7740,10 +8300,10 @@ mod tests {
let thread_id = project.threads[0].id.clone();
store.projects.push(project);
- let plan = store.activate_thread_record(&thread_id, &[]).unwrap();
+ let plan = store.activate_thread_record(&thread_id, &[], true).unwrap();
assert!(plan.needs_materialize);
let plan = store
- .activate_thread_record(&thread_id, &[plan.workspace_name.clone()])
+ .activate_thread_record(&thread_id, &[plan.workspace_name.clone()], true)
.unwrap();
assert!(!plan.needs_materialize);
}
@@ -7763,7 +8323,7 @@ mod tests {
Some(project_id.clone())
);
- let plan = store.activate_thread_record(&thread_id, &[]).unwrap();
+ let plan = store.activate_thread_record(&thread_id, &[], true).unwrap();
assert!(plan.needs_materialize);
assert_eq!(plan.project_path, dir.path());
assert_eq!(plan.workspace_name, workspace_name);
@@ -8727,6 +9287,8 @@ mod tests {
note_vault: None,
is_default: false,
client_domain: Some(domain.to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
});
store
}
@@ -9181,6 +9743,8 @@ mod tests {
note_vault: None,
is_default: false,
client_domain: Some("ams".to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
});
let owned_by_syd = store.space_ids_for_domain("syd");
@@ -9230,6 +9794,8 @@ mod tests {
note_vault: None,
is_default: false,
client_domain: Some("ssh:[email protected]".to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
});
store.spaces.push(Space {
id: "space-elsewhere".to_string(),
@@ -9238,6 +9804,8 @@ mod tests {
note_vault: None,
is_default: false,
client_domain: Some("DO AMS".to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
});
let names = vec!["ssh:[email protected]".to_string(), "DO SYD".to_string()];
@@ -9269,6 +9837,8 @@ mod tests {
note_vault: None,
is_default: false,
client_domain: Some("syd".to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
});
store.projects.push(Project {
id: "rp2".to_string(),
@@ -9303,6 +9873,8 @@ mod tests {
note_vault: None,
is_default: false,
client_domain: Some("syd".to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
});
// With nothing remembered, connecting lands on the server's first.
@@ -9367,6 +9939,8 @@ mod tests {
note_vault: None,
is_default: false,
client_domain: Some("syd".to_string()),
+ is_collection: false,
+ thread_refs: Vec::new(),
});
// Once it is known, they are hands off.
assert!(space_id_from_remote_project_id(&sibling)