Skip to content

fix: prevent terminal from stealing focus from text inputs#1615

Merged
arnestrickmann merged 1 commit intomainfrom
emdash/hai-fix-20v
Mar 28, 2026
Merged

fix: prevent terminal from stealing focus from text inputs#1615
arnestrickmann merged 1 commit intomainfrom
emdash/hai-fix-20v

Conversation

@arnestrickmann
Copy link
Copy Markdown
Contributor

@arnestrickmann arnestrickmann commented Mar 28, 2026

Summary

Fixes the terminal stealing focus from text inputs (e.g. search bars, settings fields) when viewport position is restored after a re-render.

Changes

  • Add isTextInputFocused() helper that detects when the user is actively typing in a <textarea>, <input>, or contentEditable element (excluding the terminal's own hidden textarea)
  • Guard focus() to bail out when a text input is focused, preventing the terminal from hijacking keyboard input
  • Route the post-restore focus call through focus() instead of calling this.terminal.focus() directly, so it respects the same guards

Fixes #1467

Summary by CodeRabbit

  • Bug Fixes
    • Terminal no longer steals focus from active text input fields, ensuring a smoother experience when switching between terminal and other input elements.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 28, 2026 5:32am

Request Review

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 89fc7dae-0f8e-4f9e-a0b7-67ce051bafee

📥 Commits

Reviewing files that changed from the base of the PR and between c7dbfc8 and fc760a2.

📒 Files selected for processing (1)
  • src/renderer/terminal/TerminalSessionManager.ts

📝 Walkthrough

Walkthrough

The change prevents the terminal from stealing focus from text input fields by introducing a guard condition in the focus() method. It checks if the active element is a text-input-capable field (textarea, contenteditable, or specific input types) and avoids restoring terminal focus in those cases. The focus restoration logic now uses the class method instead of directly invoking the underlying terminal's focus method.

Changes

Cohort / File(s) Summary
Terminal Focus Management
src/renderer/terminal/TerminalSessionManager.ts
Added isTextInputFocused() helper to detect user-typing inputs; modified focus() to early-return when text input is active; updated focus-restoration flow to use class method instead of direct terminal access.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A terminal once stole the stage,
From text fields on the page,
But now with care and thoughtful guard,
We check before we steal the yard,
Typing flows, no more delays! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: preventing the terminal from stealing focus from text inputs, which is the core objective of the PR.
Linked Issues check ✅ Passed The PR addresses issue #1467 by implementing focus guards [#1467] that prevent the terminal from capturing focus when text inputs are active, matching the stated objective.
Out of Scope Changes check ✅ Passed All changes are scoped to TerminalSessionManager.ts and directly address the focus-stealing problem: the helper method, focus() guard, and restoration flow modifications are all in-scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch emdash/hai-fix-20v

Comment @coderabbitai help to get the list of available commands and usage tips.

@arnestrickmann arnestrickmann merged commit 668cf9b into main Mar 28, 2026
5 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.

Bug: Text input fields randomly stop accepting keyboard input

1 participant