native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #80 from onevcat/fix/plain-folder-tab-count-badge

fix: show opened tab count for plain folder in repo header

authored by

Wei Wang and committed by
GitHub
4ff33ef4 7469598d

+89 -3
+16 -3
supacode/Features/Repositories/Views/RepositorySectionView.swift
··· 40 40 RepoHeaderRow( 41 41 name: repository.name, 42 42 isRemoving: isRemovingRepository, 43 - tabCount: repository.worktrees.reduce(0) { count, worktree in 44 - count + (terminalManager.stateIfExists(for: worktree.id)?.tabManager.tabs.count ?? 0) 45 - } 43 + tabCount: Self.openTabCount( 44 + for: repository, 45 + terminalManager: terminalManager 46 + ) 46 47 ) 47 48 .frame(maxWidth: .infinity, alignment: .leading) 48 49 .background { ··· 213 214 214 215 private var headerCellHeight: CGFloat { 215 216 34 217 + } 218 + 219 + static func openTabCount( 220 + for repository: Repository, 221 + terminalManager: WorktreeTerminalManager 222 + ) -> Int { 223 + if repository.capabilities.supportsWorktrees { 224 + return repository.worktrees.reduce(0) { count, worktree in 225 + count + (terminalManager.stateIfExists(for: worktree.id)?.tabManager.tabs.count ?? 0) 226 + } 227 + } 228 + return terminalManager.stateIfExists(for: repository.id)?.tabManager.tabs.count ?? 0 216 229 } 217 230 }
+73
supacodeTests/RepositorySectionViewTests.swift
··· 1 + import Foundation 2 + import IdentifiedCollections 3 + import Testing 4 + 5 + @testable import supacode 6 + 7 + @MainActor 8 + struct RepositorySectionViewTests { 9 + @Test func openTabCountForGitRepositorySumsAllWorktrees() { 10 + let manager = WorktreeTerminalManager(runtime: GhosttyRuntime()) 11 + let repositoryRootURL = URL(fileURLWithPath: "/tmp/repo") 12 + let mainWorktree = Worktree( 13 + id: "/tmp/repo/main", 14 + name: "main", 15 + detail: "main", 16 + workingDirectory: URL(fileURLWithPath: "/tmp/repo/main"), 17 + repositoryRootURL: repositoryRootURL 18 + ) 19 + let featureWorktree = Worktree( 20 + id: "/tmp/repo/feature", 21 + name: "feature", 22 + detail: "feature", 23 + workingDirectory: URL(fileURLWithPath: "/tmp/repo/feature"), 24 + repositoryRootURL: repositoryRootURL 25 + ) 26 + let repository = Repository( 27 + id: "/tmp/repo", 28 + rootURL: repositoryRootURL, 29 + name: "repo", 30 + kind: .git, 31 + worktrees: IdentifiedArray(uniqueElements: [mainWorktree, featureWorktree]) 32 + ) 33 + 34 + let mainState = manager.state(for: mainWorktree) 35 + let featureState = manager.state(for: featureWorktree) 36 + _ = mainState.tabManager.createTab(title: "main 1", icon: nil) 37 + _ = mainState.tabManager.createTab(title: "main 2", icon: nil) 38 + _ = featureState.tabManager.createTab(title: "feature 1", icon: nil) 39 + 40 + #expect( 41 + RepositorySectionView.openTabCount(for: repository, terminalManager: manager) 42 + == 3 43 + ) 44 + } 45 + 46 + @Test func openTabCountForPlainFolderUsesRepositoryIDTerminalState() { 47 + let manager = WorktreeTerminalManager(runtime: GhosttyRuntime()) 48 + let repositoryRootURL = URL(fileURLWithPath: "/tmp/folder") 49 + let repository = Repository( 50 + id: "/tmp/folder", 51 + rootURL: repositoryRootURL, 52 + name: "folder", 53 + kind: .plain, 54 + worktrees: [] 55 + ) 56 + let terminalTarget = Worktree( 57 + id: repository.id, 58 + name: repository.name, 59 + detail: repository.rootURL.path(percentEncoded: false), 60 + workingDirectory: repository.rootURL, 61 + repositoryRootURL: repository.rootURL 62 + ) 63 + 64 + let state = manager.state(for: terminalTarget) 65 + _ = state.tabManager.createTab(title: "folder 1", icon: nil) 66 + _ = state.tabManager.createTab(title: "folder 2", icon: nil) 67 + 68 + #expect( 69 + RepositorySectionView.openTabCount(for: repository, terminalManager: manager) 70 + == 2 71 + ) 72 + } 73 + }