MCPcopy
hub / github.com/codeaashu/claude-code / handleKeyDown

Function handleKeyDown

src/hooks/useBackgroundTaskNavigation.ts:147–240  ·  view source on GitHub ↗
(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

145 }
146
147 const handleKeyDown = (e: KeyboardEvent): void => {
148 // Escape in viewing mode:
149 // - If teammate is running: abort current work only (stops current turn, teammate stays alive)
150 // - If teammate is not running (completed/killed/failed): exit the view back to leader
151 if (e.key === 'escape' && viewSelectionMode === 'viewing-agent') {
152 e.preventDefault()
153 const taskId = viewingAgentTaskId
154 if (taskId) {
155 const task = tasks[taskId]
156 if (isInProcessTeammateTask(task) && task.status === 'running') {
157 // Abort currentWorkAbortController (stops current turn) NOT abortController (kills teammate)
158 task.currentWorkAbortController?.abort()
159 return
160 }
161 }
162 // Teammate is not running or task doesn't exist — exit the view
163 exitTeammateView(setAppState)
164 return
165 }
166
167 // Escape in selection mode: exit selection without aborting leader
168 if (e.key === 'escape' && viewSelectionMode === 'selecting-agent') {
169 e.preventDefault()
170 setAppState(prev => ({
171 ...prev,
172 viewSelectionMode: 'none',
173 selectedIPAgentIndex: -1,
174 }))
175 return
176 }
177
178 // Shift+Up/Down for teammate transcript switching (with wrapping)
179 // Index -1 represents the leader, 0+ are teammates
180 // When showSpinnerTree is true, index === teammateCount is the "hide" row
181 if (e.shift && (e.key === 'up' || e.key === 'down')) {
182 e.preventDefault()
183 if (teammateCount > 0) {
184 stepTeammateSelection(e.key === 'down' ? 1 : -1, setAppState)
185 } else if (hasNonTeammateBackgroundTasks) {
186 options?.onOpenBackgroundTasks?.()
187 }
188 return
189 }
190
191 // 'f' to view selected teammate's transcript (only in selecting mode)
192 if (
193 e.key === 'f' &&
194 viewSelectionMode === 'selecting-agent' &&
195 teammateCount > 0
196 ) {
197 e.preventDefault()
198 const selected = getSelectedTeammate()
199 if (selected) {
200 enterTeammateView(selected.taskId, setAppState)
201 }
202 return
203 }
204

Callers 1

Calls 7

isInProcessTeammateTaskFunction · 0.85
exitTeammateViewFunction · 0.85
stepTeammateSelectionFunction · 0.85
getSelectedTeammateFunction · 0.85
enterTeammateViewFunction · 0.85
preventDefaultMethod · 0.80
killMethod · 0.45

Tested by

no test coverage detected