Skip to content

fix(jetbrains): keep chat input focus while the agent works - #12

Merged
edelauna merged 1 commit into
mainfrom
fix/chat-focus-preservation
Oct 27, 2026
Merged

edelauna merged 1 commit into
mainfrom
fix/chat-focus-preservation

Conversation

@edelauna

@edelauna edelauna commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

While the user types in the chat box, the chat input loses focus on every agent turn. The user cannot type until they click the box again.

Cause

The plugin took focus when it created a terminal, opened an editor or a diff, and mounted a webview. The plugin also ignored preserveFocus for editors, diffs and terminals.

Fix

  • Add FocusRequestEpoch. A late focus request cannot override a newer one.
  • Add ManualFocusGuard. If the user moves focus, a queued deliberate show is cancelled. The guard never restores focus.
  • Add TerminalCreationFocusGuard. It restores chat focus once after a terminal is created.
  • Read preserveFocus from the wire arguments for editors, diffs and terminals. A diff sends [column, options]. A plain options map also works.
  • Keep the old webview until the new one is mounted, then retire it. Dispose uses an ownership lock.

RPC method names are unchanged.

Scope

This PR covers the plugin-side focus fixes for terminal creation, deliberate shows, editors and diffs.

Not covered: an intermittent loss of one draft character when the first editor opens. Two live runs showed it. One later full run kept all 35 sampled characters. The cause is not known. It is recorded in docs/KNOWN_ISSUES.md.

Not tested: other operating systems, and live click races.

Tests

  • 7 new unit test classes. They run headless and are in the pr.yml test list.
  • A live run against the real extension and a real model: two user turns, three commands, one applied diff, and all 35 sampled draft characters kept.
  • Details are in docs/validation/chat-focus-preservation.md.

Manual harness

jetbrains_plugin/scripts/ui-harness/ holds a dev-only harness. It runs the IDE under Xvfb and types into the real chat box.

  • Nothing ships it. No build file or plugin descriptor refers to it.
  • The relay checks a token, the Host header, the Origin header and message size. It has 12 tests.
  • The driver approves only the three fixture commands. Any other command fails the run.

Size

This PR is large. The repository sets no line limit. If you prefer, it can split into focus intent, focus restoration, webview mount and retire, and docs with harness.

@edelauna
edelauna merged commit 738db6f into main Oct 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant