Skip to content

Add right panel close controls#4148

Open
caezium wants to merge 1 commit into
pingdotgg:mainfrom
caezium:agent/right-panel-close-button
Open

Add right panel close controls#4148
caezium wants to merge 1 commit into
pingdotgg:mainfrom
caezium:agent/right-panel-close-button

Conversation

@caezium

@caezium caezium commented Jul 19, 2026

Copy link
Copy Markdown

What Changed

  • Add an explicit close button as the right-most control in the inline right-panel title-bar cluster.
  • Add a configurable rightPanel.closeActiveSurface command, bound to Cmd+W/Ctrl+W while focus is inside the right panel.
  • Route the macOS native Close Window accelerator through a stable renderer listener so any active right-panel tab closes before the app window, including terminal and preview cases where DOM focus reports the page root.
  • Preserve browser/editor-style middle-click closing for right-panel surface tabs, with regression coverage proving only button 1 closes the selected tab.
  • Harden focus ownership across preview webviews and pointer-driven focus transitions, and keep the close-surface shortcut disabled while the right panel is closed.
  • Add focused coverage for panel focus detection, shortcut precedence, close-request routing, menu dispatch, title-bar control ordering, and middle-click tab closing.

Why

The right panel has per-tab close actions but no obvious way to hide the whole panel. On macOS, Cmd+W also reaches Electron's native Close Window action instead of closing the active side-panel tab. Right-panel tabs also follow the familiar browser/editor convention: middle-click closes the selected tab without closing the panel or app window.

Closes #4146.
Closes #4147.

UI Changes

Before

Right panel before the whole-panel close control

After

Right panel with the close control at the far-right edge

Interaction

Cmd+W / whole-panel close

Watch the last active tab close and the panel reopen

The Cmd+W clip starts with one Files tab, so closing the last tab hides the panel; the panel toggle then reopens it.

Middle-click tab close

Watch middle-click close Files while Terminal and the app window stay open

This clip uses an isolated Close controls demo fixture and contains no private workspace content.

Validation

  • bun x vp test run apps/web/src/components/RightPanelTabs.test.tsx (5 tests passed)
  • bun x vp test run apps/web/src/lib/rightPanelFocus.test.ts apps/web/src/lib/nativeCloseFocus.test.ts apps/web/src/lib/rightPanelCloseRequest.test.ts apps/web/src/components/RightPanelTabs.test.tsx (4 files, 33 tests passed)
  • Targeted lint for all touched web files (passes)
  • bun run --cwd apps/web typecheck (passes)
  • Real Electron dev app: the far-right X closes the whole right panel and the panel toggle reopens it.
  • Real Electron dev app: invoking the native File → Close Window action with Files open closes the Files surface and leaves the app window open, even when accessibility focus reports only the page root.
  • Real Electron dev app: middle-clicking an inactive Files tab closes only Files while Terminal, the right panel, and the app window stay open.
  • bun x vp check (passes with 10 existing warnings in unrelated files)
  • bun x vp run typecheck (passes across all 15 workspaces)

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Changes macOS window-close and Cmd+W behavior across Electron menus and renderer focus heuristics; mistakes could close the wrong layer or skip native close fallbacks.

Overview
Adds whole-panel and surface-level close for the inline right panel: a title-bar Close control, rightPanel.closeActiveSurface (Cmd/Ctrl+W when the right panel has focus and no terminal is focused), and middle-click to close a tab via shared handleSurfaceTabAuxClick.

On macOS desktop, File → Close Window no longer uses the native close role alone. It sends close-window-or-right-panel to the main renderer when possible (dispatchMenuActionToMainWindow), otherwise performClose: through new ElectronMenu.sendActionToFirstResponder. The renderer uses nativeCloseFocus and resolveNativeCloseTarget so close hits drawer terminals, right-panel terminals/surfaces, or the panel before the window—even when DOM focus is wrong (e.g. preview webviews).

AppSidebarLayout handles the menu action by dispatching a cancelable close event; unhandled closes call window.close(). ChatView defers macOS Cmd+W to the menu path when appropriate and wires shortcut handling for layered closes.

Reviewed by Cursor Bugbot for commit 4935f60. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add right panel close controls with Cmd+W routing on macOS

  • Adds a RightPanelCloseControl UI button and rightPanel.closeActiveSurface keybinding (Cmd+W when the right panel owns focus and no terminal is focused) to close the active right-panel surface.
  • On macOS, replaces the File menu's native close role with a custom 'Close Window' item that first tries to route close-window-or-right-panel to the renderer; if unhandled, falls back to the native performClose: action via ElectronMenu.sendActionToFirstResponder.
  • Adds nativeCloseFocus tracking to determine which UI region (drawer terminal, right-panel terminal, or right-panel chrome) should handle a native close request based on recent focus and pointer activity.
  • Adds DesktopWindow.dispatchMenuActionToMainWindow to send menu actions only to the registered main window without revealing it, returning whether the action was handled.
  • Behavioral Change: Cmd+W on macOS in the desktop app is now intercepted by the renderer when the right panel owns focus, closing the active surface before the window.

Macroscope summarized 4935f60.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 18c0ce37-5013-4e64-849f-a5df0148b315

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jul 19, 2026
@caezium
caezium marked this pull request as ready for review July 19, 2026 14:16
Comment thread apps/web/src/components/ChatView.tsx Outdated
Comment thread apps/web/src/components/ChatView.tsx Outdated
@macroscopeapp

macroscopeapp Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new feature (right panel close controls with Cmd+W keybinding) involving complex focus tracking state, Electron/renderer coordination, and multiple new logic files. Additionally, an open review comment identifies a potential bug in the blur/focus handling for webviews.

You can customize Macroscope's approvability policy. Learn more.

Comment thread apps/web/src/lib/rightPanelCloseRequest.ts
Comment thread apps/web/src/components/ChatView.tsx Outdated
Comment thread apps/web/src/lib/rightPanelFocus.ts
Comment thread packages/shared/src/keybindings.ts Outdated
Comment thread apps/web/src/components/RightPanelTabs.tsx
Comment thread apps/desktop/src/window/DesktopApplicationMenu.ts
Comment thread apps/web/src/components/ChatView.tsx
Comment thread apps/web/src/components/ChatView.tsx
Comment thread apps/web/src/components/ChatView.tsx Outdated
Comment thread apps/web/src/lib/rightPanelCloseRequest.ts Outdated
Comment thread apps/web/src/lib/terminalFocus.ts Outdated
Comment thread apps/web/src/lib/nativeCloseFocus.ts
Comment thread apps/web/src/lib/nativeCloseFocus.ts
@juliusmarminge

Copy link
Copy Markdown
Member

what is the interaction demo doing? looks like you're just toggling visibility which you can already do with Mod+Shift+B ?

@caezium

caezium commented Jul 19, 2026

Copy link
Copy Markdown
Author

pressing cmd+w to close a single panel, since in the vid there was only one, the whole panel closed, sorry for the bad video, ill record another one

Comment thread apps/web/src/components/ChatView.tsx
Comment thread apps/web/src/lib/rightPanelFocus.ts
Comment thread apps/web/src/lib/nativeCloseFocus.ts
Comment thread apps/web/src/components/chat/PanelLayoutControls.tsx
@caezium

caezium commented Jul 19, 2026

Copy link
Copy Markdown
Author

Updated the PR description with a separate real-app middle-click demo. It starts with Files and Terminal open, then middle-click closes only Files while Terminal, the right panel, and the app window stay open. I also added focused regression coverage for button 1 and clarified what the existing Cmd+W clip is showing.

@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Jul 19, 2026
Comment thread apps/web/src/lib/rightPanelFocus.ts Outdated
@caezium

caezium commented Jul 19, 2026

Copy link
Copy Markdown
Author

Follow-up review fix in 85e780f: hosted preview focus is now matched by tab ID against the active right-panel preview, so a standalone preview cannot trigger the right-panel close shortcut. The focused tests cover matching and mismatched preview IDs.

window.removeEventListener("pointerdown", recordPointer, true);
window.removeEventListener("pointerup", finishNativeClosePointer, true);
window.removeEventListener("pointercancel", finishNativeClosePointer, true);
window.removeEventListener("blur", finishNativeClosePointer);

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.

Blur ends pointer focus guard early

Medium Severity

recordNativeClosePointer no longer ends the pointer transition on a microtask, and ChatView now calls finishNativeClosePointer on window blur. Electron webview focus often emits blur/focus around the click while activeElement still looks like the page root. Ending pointerTransitionActive before that click’s focusout lets recordNativeCloseFocusOut clear retainedOwner whenever document.hasFocus() is still true, so native Cmd+W can fall through to closing the window instead of the preview surface.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 85e780f. Configure here.

@caezium
caezium force-pushed the agent/right-panel-close-button branch from 85e780f to 4935f60 Compare July 19, 2026 20:38

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4935f60. Configure here.

if (element.closest(RIGHT_PANEL_SELECTOR)) return "right-panel";
if (element.tagName.toLowerCase() === "webview" || element.closest("[data-preview-viewport]")) {
return "right-panel";
}

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.

Native close ignores preview tab match

Medium Severity

The ownerForElement function incorrectly assigns right-panel ownership to any focused webview or [data-preview-viewport] without checking if it's the active right-panel preview. This allows the macOS Cmd+W shortcut to close the active right-panel surface when an inactive preview is focused, bypassing existing tab ID checks.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4935f60. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Close the active right-panel tab with Cmd+W [Feature]: Add an explicit close button to the right panel header

2 participants