Add right panel close controls#4148
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
ApprovabilityVerdict: 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. |
|
what is the interaction demo doing? looks like you're just toggling visibility which you can already do with |
|
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 |
|
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. |
|
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); |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 85e780f. Configure here.
85e780f to
4935f60
Compare
There was a problem hiding this comment.
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).
❌ 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"; | ||
| } |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 4935f60. Configure here.


What Changed
rightPanel.closeActiveSurfacecommand, bound toCmd+W/Ctrl+Wwhile focus is inside the right panel.Why
The right panel has per-tab close actions but no obvious way to hide the whole panel. On macOS,
Cmd+Walso 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
After
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 demofixture 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)bun run --cwd apps/web typecheck(passes)bun x vp check(passes with 10 existing warnings in unrelated files)bun x vp run typecheck(passes across all 15 workspaces)Checklist
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+Wwhen the right panel has focus and no terminal is focused), and middle-click to close a tab via sharedhandleSurfaceTabAuxClick.On macOS desktop, File → Close Window no longer uses the native
closerole alone. It sendsclose-window-or-right-panelto the main renderer when possible (dispatchMenuActionToMainWindow), otherwiseperformClose:through newElectronMenu.sendActionToFirstResponder. The renderer usesnativeCloseFocusandresolveNativeCloseTargetso close hits drawer terminals, right-panel terminals/surfaces, or the panel before the window—even when DOM focus is wrong (e.g. preview webviews).AppSidebarLayouthandles the menu action by dispatching a cancelable close event; unhandled closes callwindow.close().ChatViewdefers macOSCmd+Wto 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
RightPanelCloseControlUI button andrightPanel.closeActiveSurfacekeybinding (Cmd+Wwhen the right panel owns focus and no terminal is focused) to close the active right-panel surface.closerole with a custom 'Close Window' item that first tries to routeclose-window-or-right-panelto the renderer; if unhandled, falls back to the nativeperformClose:action viaElectronMenu.sendActionToFirstResponder.nativeCloseFocustracking 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.DesktopWindow.dispatchMenuActionToMainWindowto send menu actions only to the registered main window without revealing it, returning whether the action was handled.Cmd+Won 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.