@@ -70,6 +70,7 @@ public struct ChatPanelFeature: ReducerProtocol {
7070 case switchToNextTab
7171 case switchToPreviousTab
7272 case moveChatTab( from: Int , to: Int )
73+ case focusActiveChatTab
7374
7475 case chatTab( id: String , action: ChatTabItem . Action )
7576 }
@@ -117,8 +118,9 @@ public struct ChatPanelFeature: ReducerProtocol {
117118 state. chatPanelInASeparateWindow = true
118119 }
119120 state. isPanelDisplayed = true
120- return . run { _ in
121+ return . run { send in
121122 await activateExtensionService ( )
123+ await send ( . focusActiveChatTab)
122124 }
123125
124126 case let . updateChatTabInfo( chatTabInfo) :
@@ -172,14 +174,18 @@ public struct ChatPanelFeature: ReducerProtocol {
172174 return . none
173175 }
174176 state. chatTabGroup. selectedTabId = id
175- return . none
177+ return . run { send in
178+ await send ( . focusActiveChatTab)
179+ }
176180
177181 case let . appendAndSelectTab( tab) :
178182 guard !state. chatTabGroup. tabInfo. contains ( where: { $0. id == tab. id } )
179183 else { return . none }
180184 state. chatTabGroup. tabInfo. append ( tab)
181185 state. chatTabGroup. selectedTabId = tab. id
182- return . none
186+ return . run { send in
187+ await send ( . focusActiveChatTab)
188+ }
183189
184190 case . switchToNextTab:
185191 let selectedId = state. chatTabGroup. selectedTabId
@@ -192,7 +198,9 @@ public struct ChatPanelFeature: ReducerProtocol {
192198 }
193199 let targetId = state. chatTabGroup. tabInfo [ nextIndex] . id
194200 state. chatTabGroup. selectedTabId = targetId
195- return . none
201+ return . run { send in
202+ await send ( . focusActiveChatTab)
203+ }
196204
197205 case . switchToPreviousTab:
198206 let selectedId = state. chatTabGroup. selectedTabId
@@ -205,7 +213,9 @@ public struct ChatPanelFeature: ReducerProtocol {
205213 }
206214 let targetId = state. chatTabGroup. tabInfo [ previousIndex] . id
207215 state. chatTabGroup. selectedTabId = targetId
208- return . none
216+ return . run { send in
217+ await send ( . focusActiveChatTab)
218+ }
209219
210220 case let . moveChatTab( from, to) :
211221 guard from >= 0 , from < state. chatTabGroup. tabInfo. endIndex, to >= 0 ,
@@ -217,6 +227,13 @@ public struct ChatPanelFeature: ReducerProtocol {
217227 state. chatTabGroup. tabInfo. remove ( at: from)
218228 state. chatTabGroup. tabInfo. insert ( tab, at: to)
219229 return . none
230+
231+ case . focusActiveChatTab:
232+ let id = state. chatTabGroup. selectedTabInfo? . id
233+ guard let id else { return . none }
234+ return . run { send in
235+ await send ( . chatTab( id: id, action: . focus) )
236+ }
220237
221238 case let . chatTab( id, . close) :
222239 return . run { send in
0 commit comments