Repository navigation
Fix terminal blank when last pane closes (#2665) - #2670
austinywang wants to merge 3 commits into
Conversation
When closing panes down to the last remaining one, the surviving terminal went blank because the SwiftUI split-to-single-pane rebuild transiently detached the terminal surface, causing the first responder to be lost. The one-shot async focus reconcile could fire before the view was reattached, leaving no further retry. Include the surviving panel in the layout follow-up as terminalFocusPanelId so the existing retry loop keeps calling ensureFocus until the surface view successfully becomes first responder after reattachment. Closes #2665 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This review could not be run because your cubic account has exceeded the monthly review limit. If you need help restoring access, please contact contact@cubic.dev. |
📝 WalkthroughWalkthroughBroadened Workspace terminal follow-up and pane-collapse logic: focus convergence is now checked via a new helper and, when a surviving focused panel is a terminal, Workspace schedules an event-driven layout follow-up targeting that terminal; otherwise it falls back to the existing geometry reconcile path. (50 words) Changes
Sequence Diagram(s)sequenceDiagram
participant Split as BonsplitDelegate
participant WS as Workspace
participant Panel as TerminalPanel
participant Win as Window / FirstResponder
Split->>WS: pane/tab closed (didClosePane/didCloseTab)
WS->>WS: determine surviving focusedPanelId
alt surviving panel is TerminalPanel && not detaching
WS->>Panel: beginEventDrivenLayoutFollowUp(reason: "workspace.paneCollapse", includeGeometry: true)
Panel->>Win: query preferredKeyboardFocus
Win-->>Panel: current firstResponder
Panel->>WS: terminalPanelKeyboardFocusNeedsFollowUp? (compare)
alt needs follow-up
WS->>Panel: schedule focus re-apply / follow-up completion
else
WS->>WS: clear follow-up state
end
else
WS->>WS: scheduleTerminalGeometryReconcile()
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR fixes a terminal blank/input-loss bug (#2665) that occurred when closing split panes down to the last remaining pane. The root cause was the SwiftUI split-to-single-pane rebuild transiently detaching the terminal surface mid-focus-reconcile; the fix passes the surviving panel as Confidence Score: 5/5Safe to merge; fix is surgical, well-commented, and handles all relevant edge cases No P0 or P1 findings. The two change sites are symmetric and correct: pane-collapse detection in didCloseTab uses the explicit !bonsplitController.allPaneIds.contains(pane) guard while didClosePane implicitly implies a pane was removed. The includeGeometry flag preserves the prior geometry-reconcile behavior. No double-fire risk is introduced—the trailing scheduleFocusReconcile() calls were already present before this PR. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant BonsplitController
participant Workspace
participant SwiftUI
participant TerminalSurface
User->>BonsplitController: Close last tab in pane
BonsplitController->>Workspace: didCloseTab(pane collapsed)
Workspace->>Workspace: applyTabSelection(survivingPane)
note over Workspace: isDetaching=false,<br/>pane no longer in allPaneIds
Workspace->>Workspace: beginEventDrivenLayoutFollowUp(<br/>terminalFocusPanelId=survivingPanelId,<br/>includeGeometry=true)
Workspace->>SwiftUI: layout observers installed
SwiftUI-->>Workspace: split view rebuilds (detaches surface)
TerminalSurface-->>Workspace: terminalSurfaceHostedViewDidMoveToWindow
Workspace->>Workspace: scheduleLayoutFollowUpAttempt()
Workspace->>TerminalSurface: ensureFocus() [retry loop]
TerminalSurface-->>User: first responder restored ✓
Reviews (1): Last reviewed commit: "Fix terminal blank when last pane closes..." | Re-trigger Greptile |
The focusPanel layout follow-up with terminalFocusPanelId was gated to .terminalFirstResponder trigger only. When creating a new workspace via Cmd+T, the trigger is .standard, so no focus retry loop was set up. The new terminal surface goes through portal attach/detach cycles and the one-shot ensureFocus fires before the view is ready. Extend the follow-up to fire for any trigger when the terminal is not yet first responder, so the retry loop handles portal churn on workspace creation the same way it handles split-close churn. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
terminalFocusPanelId, so the existing retry loop (triggered byterminalSurfaceHostedViewDidMoveToWindow) keeps callingensureFocusuntil the surface view successfully becomes first responder after reattachmentTest plan
Closes #2665
🤖 Generated with Claude Code
Note
Medium Risk
Adjusts workspace focus/layout follow-up logic around terminal first-responder handling and split-view rebuilds; regressions could leave focus stuck or cause extra layout retries in terminal panels.
Overview
Prevents the surviving terminal from going blank after collapsing split panes by starting an event-driven layout follow-up that keeps re-applying
ensureFocusuntil the terminal’s preferred keyboard target is active.This expands terminal focus follow-up beyond the
.terminalFirstRespondertrigger, addsterminalPanelKeyboardFocusNeedsFollowUp(checks window first responder vs. terminal preferred focus), and uses it to gate both follow-up scheduling and clearing. Pane close/collapse paths now preferbeginEventDrivenLayoutFollowUp(... includeGeometry: true)for the surviving terminal (skipping detach flows), falling back to the existing geometry reconcile otherwise.Reviewed by Cursor Bugbot for commit f8e480a. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes blank terminals and lost input when collapsing to a single pane or creating a new workspace (Cmd+T). Keeps the surviving terminal—or its find field—in focus so input works (fixes #2665).
terminalFocusPanelIdso focus is reapplied after the split rebuild; applies to tab-close and pane-collapse; skipped on detach..terminalFirstResponder; covers new workspace creation.Written for commit f8e480a. Summary will update on new commits.
Summary by CodeRabbit