Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions supacode/Commands/WindowCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,28 @@ struct WindowCommands: Commands {
@FocusedValue(\.closeSurfaceAction) private var closeSurfaceAction
@FocusedValue(\.closeTabAction) private var closeTabAction
@FocusedValue(\.terminateAllTerminalSessionsAction) private var terminateAllTerminalSessionsAction
@FocusedValue(\.showNextTabAction) private var showNextTabAction
@FocusedValue(\.showPreviousTabAction) private var showPreviousTabAction

var body: some Commands {
// Tab navigation lives in the Window menu so it matches macOS conventions
// and can be rebound from System Settings ▸ Keyboard ▸ Shortcuts (issue #418).
CommandGroup(before: .windowArrangement) {
Button("Show Next Tab") {
showNextTabAction?()
}
.ghosttyKeyboardShortcut("next_tab", in: ghosttyShortcuts)
.disabled(showNextTabAction?.isEnabled != true)

Button("Show Previous Tab") {
showPreviousTabAction?()
}
.ghosttyKeyboardShortcut("previous_tab", in: ghosttyShortcuts)
.disabled(showPreviousTabAction?.isEnabled != true)

Divider()
}

let closeSurfaceHotkey = ghosttyShortcuts.keyboardShortcut(for: "close_surface")
let isCloseSurfaceOverlapping = closeSurfaceHotkey?.key == "w" && closeSurfaceHotkey?.modifiers == .command

Expand Down Expand Up @@ -50,3 +70,25 @@ extension FocusedValues {
set { self[TerminateAllTerminalSessionsActionKey.self] = newValue }
}
}

private struct ShowNextTabActionKey: FocusedValueKey {
typealias Value = FocusedAction<Void>
}

extension FocusedValues {
var showNextTabAction: FocusedAction<Void>? {
get { self[ShowNextTabActionKey.self] }
set { self[ShowNextTabActionKey.self] = newValue }
}
}

private struct ShowPreviousTabActionKey: FocusedValueKey {
typealias Value = FocusedAction<Void>
}

extension FocusedValues {
var showPreviousTabAction: FocusedAction<Void>? {
get { self[ShowPreviousTabActionKey.self] }
set { self[ShowPreviousTabActionKey.self] = newValue }
}
}
3 changes: 2 additions & 1 deletion supacode/Features/App/Models/WorktreeMenuSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ extension AppFeature.Action {
.worktreeSettingsLoaded, .openSelectedWorktree, .revealInFinder,
.openWorktree, .openWorktreeFailed, .requestQuit,
.requestTerminateAllTerminalSessions, .newTerminal,
.selectTerminalTabAtIndex, .splitTerminal, .jumpToLatestUnread,
.selectTerminalTabAtIndex, .splitTerminal, .showNextTab, .showPreviousTab,
.jumpToLatestUnread,
.menuBarWorktreeSelected, .markAllNotificationsRead, .runScript, .runNamedScript,
.manageRepositoryScripts,
.stopScript, .stopRunScripts, .closeTab, .closeSurface,
Expand Down
24 changes: 24 additions & 0 deletions supacode/Features/App/Reducer/AppFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ struct AppFeature {
case newTerminal
case selectTerminalTabAtIndex(Int)
case splitTerminal(TerminalSplitMenuDirection)
case showNextTab
case showPreviousTab
case jumpToLatestUnread
case menuBarWorktreeSelected(worktreeID: Worktree.ID)
case markAllNotificationsRead
Expand Down Expand Up @@ -898,6 +900,28 @@ struct AppFeature {
await terminalClient.send(.performBindingAction(worktree, action: direction.ghosttyBinding))
}

// Route through the same Ghostty binding the keybinding uses, so custom
// `next_tab` / `previous_tab` bindings are honored (see issue #418).
case .showNextTab:
guard let worktree = state.repositories.worktree(for: state.repositories.selectedWorktreeID),
!worktree.isMissing
else {
return .none
}
return .run { _ in
await terminalClient.send(.performBindingAction(worktree, action: "next_tab"))
}

case .showPreviousTab:
guard let worktree = state.repositories.worktree(for: state.repositories.selectedWorktreeID),
!worktree.isMissing
else {
return .none
}
return .run { _ in
await terminalClient.send(.performBindingAction(worktree, action: "previous_tab"))
}

case .jumpToLatestUnread:
guard let location = terminalClient.latestUnreadNotification() else {
jumpLogger.debug("jumpToLatestUnread invoked with no unread notifications.")
Expand Down
6 changes: 6 additions & 0 deletions supacode/Features/Repositories/Views/WorktreeDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ struct WorktreeDetailView: View {
.focusedAction(\.closeTabAction, enabled: hasActiveWorktree) {
store.send(.closeTab)
}
.focusedAction(\.showNextTabAction, enabled: hasActiveWorktree) {
store.send(.showNextTab)
}
.focusedAction(\.showPreviousTabAction, enabled: hasActiveWorktree) {
store.send(.showPreviousTab)
}
.focusedAction(\.closeSurfaceAction, enabled: hasActiveWorktree) {
store.send(.closeSurface)
}
Expand Down
94 changes: 94 additions & 0 deletions supacodeTests/AppFeatureTabNavigationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import ComposableArchitecture
import DependenciesTestSupport
import Foundation
import Testing

@testable import SupacodeSettingsFeature
@testable import supacode

@MainActor
struct AppFeatureTabNavigationTests {
@Test(.dependencies) func showNextTabForwardsNextTabBinding() async {
let worktree = makeWorktree()
let sent = LockIsolated<[TerminalClient.Command]>([])
let store = TestStore(
initialState: AppFeature.State(
repositories: makeRepositoriesState(worktree: worktree),
settings: SettingsFeature.State()
)
) {
AppFeature()
} withDependencies: {
$0.terminalClient.send = { command in
sent.withValue { $0.append(command) }
}
}

await store.send(.showNextTab)
await store.finish()
#expect(sent.value == [.performBindingAction(worktree, action: "next_tab")])
}

@Test(.dependencies) func showPreviousTabForwardsPreviousTabBinding() async {
let worktree = makeWorktree()
let sent = LockIsolated<[TerminalClient.Command]>([])
let store = TestStore(
initialState: AppFeature.State(
repositories: makeRepositoriesState(worktree: worktree),
settings: SettingsFeature.State()
)
) {
AppFeature()
} withDependencies: {
$0.terminalClient.send = { command in
sent.withValue { $0.append(command) }
}
}

await store.send(.showPreviousTab)
await store.finish()
#expect(sent.value == [.performBindingAction(worktree, action: "previous_tab")])
}

@Test(.dependencies) func tabNavigationWithoutSelectionIsNoop() async {
let store = TestStore(
initialState: AppFeature.State(
repositories: RepositoriesFeature.State(),
settings: SettingsFeature.State()
)
) {
AppFeature()
} withDependencies: {
$0.terminalClient.send = { _ in
Issue.record("terminalClient.send should not be called without a selected worktree")
}
}

await store.send(.showNextTab)
await store.send(.showPreviousTab)
await store.finish()
}

private func makeWorktree() -> Worktree {
Worktree(
id: "/tmp/repo/wt-1",
name: "wt-1",
detail: "detail",
workingDirectory: URL(fileURLWithPath: "/tmp/repo/wt-1"),
repositoryRootURL: URL(fileURLWithPath: "/tmp/repo")
)
}

private func makeRepositoriesState(worktree: Worktree) -> RepositoriesFeature.State {
let repository = Repository(
id: "/tmp/repo",
rootURL: URL(fileURLWithPath: "/tmp/repo"),
name: "repo",
worktrees: [worktree]
)
var state = RepositoriesFeature.State()
state.repositories = [repository]
state.selection = .worktree(worktree.id)
return state
}
}
Loading