Skip to content

Commit c59ae6e

Browse files
committed
Move with other handlers
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent c62f8a0 commit c59ae6e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pkg/tui/handlers.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,18 @@ func (a *appModel) handleCycleAgent() (tea.Model, tea.Cmd) {
198198

199199
// Cycle to the next agent (wrap around to 0 if at the end)
200200
nextIndex := (currentIndex + 1) % len(availableAgents)
201-
return a.switchToAgentByIndex(nextIndex)
201+
return a.handleSwitchToAgentByIndex(nextIndex)
202+
}
203+
204+
func (a *appModel) handleSwitchToAgentByIndex(index int) (tea.Model, tea.Cmd) {
205+
availableAgents := a.sessionState.AvailableAgents()
206+
if index >= 0 && index < len(availableAgents) {
207+
agentName := availableAgents[index].Name
208+
if agentName != a.sessionState.CurrentAgentName() {
209+
return a, core.CmdHandler(messages.SwitchAgentMsg{AgentName: agentName})
210+
}
211+
}
212+
return a, nil
202213
}
203214

204215
// Toggles

pkg/tui/tui.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,9 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
478478
default:
479479
// Handle ctrl+1 through ctrl+9 for quick agent switching
480480
if index := parseCtrlNumberKey(msg); index >= 0 {
481-
return a.switchToAgentByIndex(index)
481+
return a.handleSwitchToAgentByIndex(index)
482482
}
483+
483484
updated, cmd := a.chatPage.Update(msg)
484485
a.chatPage = updated.(chat.Page)
485486
return a, cmd
@@ -495,18 +496,6 @@ func parseCtrlNumberKey(msg tea.KeyPressMsg) int {
495496
return -1
496497
}
497498

498-
// switchToAgentByIndex switches to the agent at the given index
499-
func (a *appModel) switchToAgentByIndex(index int) (tea.Model, tea.Cmd) {
500-
availableAgents := a.sessionState.AvailableAgents()
501-
if index >= 0 && index < len(availableAgents) {
502-
agentName := availableAgents[index].Name
503-
if agentName != a.sessionState.CurrentAgentName() {
504-
return a, core.CmdHandler(messages.SwitchAgentMsg{AgentName: agentName})
505-
}
506-
}
507-
return a, nil
508-
}
509-
510499
// View renders the complete application interface
511500
func (a *appModel) View() tea.View {
512501
windowTitle := a.windowTitle()

0 commit comments

Comments
 (0)