(tabs: Tab[], scope: Scope, server: ServerConnection.Key)
| 181 | type Scope = { draftID: string } | { dir: string; id?: string } |
| 182 | |
| 183 | export function selectPromptTab(tabs: Tab[], scope: Scope, server: ServerConnection.Key) { |
| 184 | if ("draftID" in scope) return tabs.find((tab) => tab.type === "draft" && tab.draftID === scope.draftID) |
| 185 | if (!scope.id) return |
| 186 | return ( |
| 187 | tabs.find((tab) => tab.type === "session" && tab.server === server && tab.sessionId === scope.id) ?? |
| 188 | ({ type: "session", server, sessionId: scope.id } satisfies Tab) |
| 189 | ) |
| 190 | } |
| 191 | |
| 192 | function scopeKey(scope: Scope) { |
| 193 | if ("draftID" in scope) return `draft:${scope.draftID}` |
no test coverage detected