Skip to content

Don't steal focus while navigating an AI block's code diff#12107

Merged
advait-m merged 2 commits into
masterfrom
advait/fix-ai-block-focus-steal
Jun 3, 2026
Merged

Don't steal focus while navigating an AI block's code diff#12107
advait-m merged 2 commits into
masterfrom
advait/fix-ai-block-focus-steal

Conversation

@advait-m
Copy link
Copy Markdown
Member

@advait-m advait-m commented Jun 2, 2026

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:

  • Added TerminalView::is_navigating_ai_block.
  • focus_ai_block_if_self_focused skips 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_focus excludes the "navigating an AI block" case, alongside the existing find-bar / block-filter exclusions.
  • try_steal_focus is 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

  • I have manually tested my changes locally with ./script/run

cargo fmt and cargo clippy -p warp -- -D warnings pass.

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

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>
@cla-bot cla-bot Bot added the cla-signed label Jun 2, 2026
@advait-m advait-m marked this pull request as ready for review June 2, 2026 23:06
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented Jun 2, 2026

@advait-m

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@advait-m advait-m requested a review from vorporeal June 2, 2026 23:09
Comment thread app/src/terminal/view.rs
if !ctx.is_self_or_child_focused() {
return;
}
let target_needs_attention = block.as_ref(ctx).is_blocked_on_user_confirmation(ctx);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread app/src/terminal/view.rs Outdated
Comment thread app/src/terminal/view.rs Outdated
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>
@advait-m advait-m enabled auto-merge (squash) June 3, 2026 22:21
@advait-m advait-m merged commit edf8354 into master Jun 3, 2026
27 checks passed
@advait-m advait-m deleted the advait/fix-ai-block-focus-steal branch June 3, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants