Skip to content

fix(terminal): forward key events in panel host container to fix Esc key - #1692

Closed
BillionClaw wants to merge 1 commit into
manaflow-ai:mainfrom
BillionClaw:clawoss/fix/esc-in-panels
Closed

BillionClaw wants to merge 1 commit into
manaflow-ai:mainfrom
BillionClaw:clawoss/fix/esc-in-panels

Conversation

@BillionClaw

@BillionClaw BillionClaw commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1610 - Esc key not working inside panels.

Problem

When a terminal is embedded in a panel (via the bonsplit layout system), key events were not being properly routed to the terminal view. This was because the HostContainerView (the SwiftUI anchor for the portal-hosted terminal) did not forward key events to the actual GhosttyNSView that handles terminal input.

Solution

Modified HostContainerView in GhosttyTerminalView.swift to forward key events to the hosted terminal surface view:

  1. Added key event forwarding methods: keyDown, keyUp, flagsChanged, and performKeyEquivalent now forward events to the terminal surface view.

  2. Added acceptsFirstResponder override: Returns true so the container can receive key events.

  3. Added becomeFirstResponder override: Transfers focus directly to the terminal view when the container becomes first responder.

  4. Added public terminalSurfaceView accessor: Exposes the underlying GhosttyNSView from GhosttySurfaceScrollView for event forwarding.

  5. Connected hostedView reference: Sets the hosted view on HostContainerView during updateNSView so it can forward events.

Testing

This fix ensures that keys like Escape are properly routed to the terminal when using panels, allowing terminal applications (like vim, less, etc.) to receive Esc key input correctly.

Related


Summary by cubic

Forward key events from the panel host container to the terminal surface view so Esc and other keys work when the terminal is embedded in panels. Fixes #1610.

  • Bug Fixes
    • Host container forwards keyDown/keyUp/flagsChanged/performKeyEquivalent to the hosted terminal.
    • Allows first responder and transfers focus to the terminal on becomeFirstResponder.
    • Adds a terminalSurfaceView accessor and wires hostedView during updateNSView for event routing.

Written for commit d9cb478. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed keyboard input routing for embedded terminal views to ensure all keyboard events, including the Escape key, are properly handled and processed in terminal panels.

The HostContainerView in GhosttyTerminalView now forwards key events to the
hosted terminal surface view. This ensures that keys like Escape work properly
inside panels by routing events from the SwiftUI anchor view to the actual
terminal view hosted in the portal window layer.

Changes:
- Added key event forwarding methods (keyDown, keyUp, flagsChanged, performKeyEquivalent)
- Added acceptsFirstResponder override to enable key event reception
- Added becomeFirstResponder override to transfer focus to terminal view
- Added public terminalSurfaceView accessor on GhosttySurfaceScrollView
- Connected hostedView reference in HostContainerView during updateNSView

Fixes manaflow-ai#1610
@vercel

vercel Bot commented Mar 18, 2026

Copy link
Copy Markdown

@BillionClaw is attempting to deploy a commit to the Manaflow Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps greptile-apps Bot left a comment

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.

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

@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3dfd0ac0-2340-4506-ab57-acf1c0c0df9f

📥 Commits

Reviewing files that changed from the base of the PR and between 55cb5c6 and d9cb478.

📒 Files selected for processing (1)
  • Sources/GhosttyTerminalView.swift

📝 Walkthrough

Walkthrough

HostContainerView now forwards keyboard events (keyDown, keyUp, flagsChanged, performKeyEquivalent) to the underlying Ghostty terminal surface, enabling proper event handling within panel-hosted terminals. A weak reference to hostedView and a public accessor terminalSurfaceView are added to support this event routing mechanism.

Changes

Cohort / File(s) Summary
Keyboard Event Forwarding
Sources/GhosttyTerminalView.swift
Added weak hostedView reference and keyboard event forwarding methods (keyDown, keyUp, flagsChanged, performKeyEquivalent) to route input from HostContainerView to GhosttyNSView. Implemented first responder delegation and exposed new public terminalSurfaceView accessor.

Sequence Diagram

sequenceDiagram
    actor User
    participant Panel as SwiftUI Panel
    participant HCV as HostContainerView
    participant ScrollView as GhosttySurfaceScrollView
    participant Terminal as GhosttyNSView

    User->>Panel: Press Escape key
    Panel->>HCV: keyDown event
    HCV->>HCV: canBecomeFirstResponder?
    HCV->>ScrollView: Forward keyDown via hostedView
    ScrollView->>Terminal: Pass to terminal surface
    Terminal->>Terminal: Process Escape input
    Terminal->>User: Dialog closes
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Keyboard keys now find their way,
Through panels bright, they dance and play,
Escape unlocks the lazygit door,
With forwarded events, we ask for more!
Events route true, from view to core, 🎹✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing key event forwarding in the panel host container to resolve the Esc key issue.
Description check ✅ Passed The description covers the problem, solution, and testing approach comprehensively, though it lacks a demo video and explicit checklist confirmation.
Linked Issues check ✅ Passed The code changes directly address issue #1610 by implementing key event forwarding to ensure Esc and other keys reach the terminal when embedded in panels.
Out of Scope Changes check ✅ Passed All changes are scoped to GhosttyTerminalView.swift and directly relate to fixing key event forwarding in HostContainerView for the panel host use case.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

@BillionClaw

Copy link
Copy Markdown
Contributor Author

Closing per repository blocklist: maintainer threatened to ban. All submissions to this repo have been suspended.

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.

Esc does not work inside panels

1 participant