Don't steal focus while navigating an AI block's code diff#12107
Conversation
Automatic focus events (request boundaries, block-finished) re-targeted the active AI block and bounced focus to the prompt input, interrupting users navigating diff hunks in an earlier block. Guard focus_ai_block_if_self_focused and redetermine_terminal_focus via a new is_navigating_ai_block helper so they don't move focus while the user is navigating an AI block, unless the target block is blocked on user input. try_steal_focus is left unchanged. Co-Authored-By: Oz <oz-agent@warp.dev>
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR adjusts terminal focus handling so automatic AI-block focus changes no longer steal focus while the user is navigating another AI block's code diff, while preserving focus stealing for blocks that are blocked on user confirmation.
Concerns
- No blocking correctness, security, or spec-alignment concerns found in the annotated diff. The PR description includes a Loom recording for the user-visible behavior change, satisfying the repository's visual-evidence requirement.
Verdict
Found: 0 critical, 0 important, 0 suggestions
Approve
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
| if !ctx.is_self_or_child_focused() { | ||
| return; | ||
| } | ||
| let target_needs_attention = block.as_ref(ctx).is_blocked_on_user_confirmation(ctx); |
There was a problem hiding this comment.
i think the complexity will make it out-of-scope for this, but in theory, i think a block that requires user confirmation should only get focused if it is on-screen?
could simplify to "only gets focused if the scroll position is at the top/bottom" - if the scroll position is elsewhere, it indicates that the user is engaged with other parts of the blocklist. (and if we did that, i could imagine us adjusting focus when the user scrolls all the way to the top/bottom)
again, i think as-written is fine for now, but we could do some more tuning here in a follow-up.
There was a problem hiding this comment.
gotcha - yeah being aware of on vs off screen would be good here; filed https://linear.app/warpdotdev/issue/APP-4658/only-focus-blocks-for-needs-user-attention-if-its-on-screen to track this
Per review feedback: invert the condition in focus_ai_block_if_self_focused so the steal is guarded inline rather than via a negative early return, and rename is_navigating_ai_block -> is_any_ai_block_focused for clarity. No behavior change. Co-Authored-By: Oz <oz-agent@warp.dev>
Loom: https://www.loom.com/share/e957af04b66c40639ee7eb8498b485cc
Description
Fixes focus being stolen to the prompt input while navigating an AI block's code diff hunks (up/down) during an agent turn.
At a "request boundary" mid-turn (one response stream finishes / a new exchange streams in), automatic focus handling re-targeted the active AI block; since that block has nothing actionable and the input is visible during streaming, focus bounced to the input — interrupting diff-hunk navigation on an earlier block. The same happened at end-of-turn via
redetermine_terminal_focus.How:
TerminalView::is_navigating_ai_block.focus_ai_block_if_self_focusedskips the steal when focus is inside an AI block, unless the target block is blocked on user input (so approval gates still grab focus).redetermine_terminal_focusexcludes the "navigating an AI block" case, alongside the existing find-bar / block-filter exclusions.try_steal_focusis intentionally left unchanged.This appears to be a long-standing issue (the focus code predates the public-release squash), not a regression from prompt queueing.
Linked Issue
N/A — surfaced via internal Slack report (focus stealing while reviewing agent code diffs).
Testing
./script/runcargo fmtandcargo clippy -p warp -- -D warningspass.CHANGELOG-BUG-FIX: Fixed focus jumping to the prompt input while navigating an AI block's code diff hunks with the arrow keys during an agent turn.
Co-Authored-By: Oz oz-agent@warp.dev