Skip to content

Commit d29a08b

Browse files
committed
Support switching chat tab with command+shift+[]
1 parent 5c9ed4c commit d29a08b

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ struct ChatTabBar: View {
113113
createButton
114114
}
115115
}
116+
.background {
117+
Button(action: { store.send(.switchToNextTab) }) { EmptyView() }
118+
.opacity(0)
119+
.keyboardShortcut("]", modifiers: [.command, .shift])
120+
Button(action: { store.send(.switchToPreviousTab) }) { EmptyView() }
121+
.opacity(0)
122+
.keyboardShortcut("[", modifiers: [.command, .shift])
123+
}
116124
}
117125

118126
@ViewBuilder

Core/Sources/SuggestionWidget/FeatureReducers/ChatPanelFeature.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public struct ChatPanelFeature: ReducerProtocol {
7171
case createNewTapButtonClicked(kind: ChatTabKind?)
7272
case tabClicked(id: String)
7373
case appendAndSelectTab(BaseChatTab)
74+
case switchToNextTab
75+
case switchToPreviousTab
7476
}
7577

7678
@Dependency(\.suggestionWidgetControllerDependency) var suggestionWidgetControllerDependency
@@ -146,7 +148,7 @@ public struct ChatPanelFeature: ReducerProtocol {
146148
state.isPanelDisplayed = false
147149
}
148150
return .none
149-
151+
150152
case .createNewTapButtonHovered:
151153
state.chatTapGroup.tabCollection = chatTabBuilderCollection()
152154
return .none
@@ -168,6 +170,32 @@ public struct ChatPanelFeature: ReducerProtocol {
168170
state.chatTapGroup.tabs.append(tab)
169171
state.chatTapGroup.selectedTabId = tab.id
170172
return .none
173+
174+
case .switchToNextTab:
175+
let selectedId = state.chatTapGroup.selectedTabId
176+
guard let index = state.chatTapGroup.tabInfo
177+
.firstIndex(where: { $0.id == selectedId })
178+
else { return .none }
179+
let nextIndex = index + 1
180+
if nextIndex >= state.chatTapGroup.tabInfo.endIndex {
181+
return .none
182+
}
183+
let targetId = state.chatTapGroup.tabInfo[nextIndex].id
184+
state.chatTapGroup.selectedTabId = targetId
185+
return .none
186+
187+
case .switchToPreviousTab:
188+
let selectedId = state.chatTapGroup.selectedTabId
189+
guard let index = state.chatTapGroup.tabInfo
190+
.firstIndex(where: { $0.id == selectedId })
191+
else { return .none }
192+
let previousIndex = index - 1
193+
if previousIndex < 0 || previousIndex >= state.chatTapGroup.tabInfo.endIndex {
194+
return .none
195+
}
196+
let targetId = state.chatTapGroup.tabInfo[previousIndex].id
197+
state.chatTapGroup.selectedTabId = targetId
198+
return .none
171199
}
172200
}
173201
}

0 commit comments

Comments
 (0)