summaryrefslogtreecommitdiffhomepage
path: root/src/features/tabs
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/tabs')
-rw-r--r--src/features/tabs/tabs-store.svelte.ts6
-rw-r--r--src/features/tabs/tabs.ts11
2 files changed, 17 insertions, 0 deletions
diff --git a/src/features/tabs/tabs-store.svelte.ts b/src/features/tabs/tabs-store.svelte.ts
index cba527e..2e876f9 100644
--- a/src/features/tabs/tabs-store.svelte.ts
+++ b/src/features/tabs/tabs-store.svelte.ts
@@ -4,6 +4,7 @@ import {
closeTab as reduceCloseTab,
createTab as reduceCreateTab,
newDraft as reduceNewDraft,
+ openTab as reduceOpenTab,
selectTab as reduceSelectTab,
setModel as reduceSetModel,
setTitle as reduceSetTitle,
@@ -21,6 +22,8 @@ export interface TabsStore {
readonly activeTab: Tab | null;
newDraft(): void;
createTab(tab: Tab): void;
+ /** Add a tab WITHOUT focusing it (for `conversation.open`). No-op if already open. */
+ openTab(tab: Tab): void;
selectTab(conversationId: string): void;
closeTab(conversationId: string): void;
setModel(conversationId: string, model: string): void;
@@ -51,6 +54,9 @@ export function createTabsStore(storage: TabsStorage): TabsStore {
createTab(tab: Tab): void {
apply(reduceCreateTab(state, tab));
},
+ openTab(tab: Tab): void {
+ apply(reduceOpenTab(state, tab));
+ },
selectTab(conversationId: string): void {
apply(reduceSelectTab(state, conversationId));
},
diff --git a/src/features/tabs/tabs.ts b/src/features/tabs/tabs.ts
index 61ae58e..3360d3f 100644
--- a/src/features/tabs/tabs.ts
+++ b/src/features/tabs/tabs.ts
@@ -27,6 +27,17 @@ export function createTab(state: TabsState, tab: Tab): TabsState {
return { tabs, activeConversationId: tab.conversationId };
}
+/**
+ * Add a tab WITHOUT switching the active conversation — used by the
+ * `conversation.open` WS broadcast (CLI `--open`): the tab appears in the
+ * strip but the user stays on their current tab. No-op if already open.
+ */
+export function openTab(state: TabsState, tab: Tab): TabsState {
+ const exists = state.tabs.some((t) => t.conversationId === tab.conversationId);
+ if (exists) return state;
+ return { tabs: [...state.tabs, tab], activeConversationId: state.activeConversationId };
+}
+
export function selectTab(state: TabsState, conversationId: string): TabsState {
return { ...state, activeConversationId: conversationId };
}