Skip to content

Commit 77d1b67

Browse files
committed
Merge branch 'feature/chat-panel-keyboard-shortcuts' into develop
2 parents 5c9ed4c + f118cf7 commit 77d1b67

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

Core/Sources/SuggestionWidget/ChatWindowView.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ struct ChatWindowView: View {
6969
}
7070
}
7171

72+
private extension View {
73+
func hideScrollIndicator() -> some View {
74+
if #available(macOS 13.0, *) {
75+
return scrollIndicators(.hidden)
76+
} else {
77+
return self
78+
}
79+
}
80+
}
81+
7282
struct ChatTabBar: View {
7383
let store: StoreOf<ChatPanelFeature>
7484

@@ -107,12 +117,21 @@ struct ChatTabBar: View {
107117
}
108118
}
109119
}
120+
.hideScrollIndicator()
110121

111122
Divider()
112123

113124
createButton
114125
}
115126
}
127+
.background {
128+
Button(action: { store.send(.switchToNextTab) }) { EmptyView() }
129+
.opacity(0)
130+
.keyboardShortcut("]", modifiers: [.command, .shift])
131+
Button(action: { store.send(.switchToPreviousTab) }) { EmptyView() }
132+
.opacity(0)
133+
.keyboardShortcut("[", modifiers: [.command, .shift])
134+
}
116135
}
117136

118137
@ViewBuilder
@@ -300,6 +319,11 @@ struct ChatWindowView_Previews: PreviewProvider {
300319
tabs: [
301320
FakeChatTab(id: "1", title: "Hello I am a chatbot"),
302321
EmptyChatTab(id: "2"),
322+
EmptyChatTab(id: "3"),
323+
EmptyChatTab(id: "4"),
324+
EmptyChatTab(id: "5"),
325+
EmptyChatTab(id: "6"),
326+
EmptyChatTab(id: "7"),
303327
],
304328
selectedTabId: "1"
305329
),

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
}

Pro

Submodule Pro updated from fd23e0f to dfbf605

0 commit comments

Comments
 (0)