Skip to content

CMD+W to close tab - #92

Merged
Kitenite merged 4 commits into
mainfrom
more-hotkeys-ju2l
Nov 17, 2025
Merged

Kitenite merged 4 commits into
mainfrom
more-hotkeys-ju2l

Conversation

@Kitenite

@Kitenite Kitenite commented Nov 16, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added Cmd+W keyboard shortcut to close the current terminal tab.

@coderabbitai

coderabbitai Bot commented Nov 16, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This change introduces a terminal close feature accessible via Cmd+W keyboard shortcut. It extends the shortcuts system with a new closeTerminal handler, threads workspace and worktree context through the component hierarchy to Terminal, and implements tab deletion via IPC when the shortcut is invoked. Documentation is updated to reflect the new shortcut.

Changes

Cohort / File(s) Summary
Documentation
AGENTS.md
Added Cmd+W keyboard shortcut documentation for closing terminal under Keyboard Shortcuts System section.
Shortcuts System
apps/desktop/src/renderer/lib/shortcuts.ts
Added closeTerminal: () => void property to ShortcutHandlers interface. Updated createTerminalShortcuts function signature to accept both clearTerminal and closeTerminal handlers. Registered Meta+W keyboard shortcut to invoke closeTerminal handler.
Terminal Context & Implementation
apps/desktop/src/renderer/screens/main/components/MainContent/TabContent.tsx, apps/desktop/src/renderer/screens/main/components/MainContent/Terminal.tsx
Added workspaceId and worktreeId optional props to Terminal component signature. Updated TabContent to pass these props to Terminal instance. Implemented closeTerminal handler in Terminal that invokes "tab-delete" IPC with workspace/worktree/tab identifiers and includes error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant System as Keyboard System
    participant Terminal as Terminal Component
    participant IPC as IPC Renderer
    participant Main as Main Process

    User->>System: Press Cmd+W
    System->>Terminal: Trigger closeTerminal shortcut handler
    Terminal->>Terminal: Check terminalId, workspaceId, worktreeId available
    Terminal->>IPC: invoke("tab-delete", {workspaceId, worktreeId, tabId})
    IPC->>Main: Forward tab-delete request
    Main->>Main: Delete tab
    Main-->>IPC: Success/Error response
    IPC-->>Terminal: Handle response (log if error)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Interface extension: Review the new closeTerminal handler signature and its integration into ShortcutHandlers
  • Prop threading: Verify workspaceId and worktreeId are correctly passed from TabContent through to Terminal
  • IPC integration: Examine the closeTerminal implementation in Terminal.tsx, particularly the async IPC call, null checks, and error handling logic
  • Shortcut registration: Confirm Meta+W binding is properly configured and doesn't conflict with existing shortcuts

Poem

🐰 A terminal door now springs shut with a key,
Cmd+W brings swift closure, wild and free!
Through workspaces hopping, contexts align,
IPC whispers delete—tabs end by design.
One shortcut, one feature, one happy machine! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided; all required template sections (Description, Related Issues, Type of Change, Testing, etc.) are missing. Add a complete PR description following the template, including what changes were made, related issues, type of change, and testing details.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'CMD+W to close tab' directly and specifically describes the main change: adding a keyboard shortcut to close tabs, which is the primary feature across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch more-hotkeys-ju2l

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

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
AGENTS.md (1)

262-265: Clarify overlap between tab Cmd+W and terminal Cmd+W in docs

You now list Cmd+W both for closing tabs and for closing the current terminal. If the behavior is effectively “close the active tab (including terminal tabs)”, consider clarifying the wording or adding a brief note so users don’t wonder if these are distinct actions.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04bcd04 and dcba245.

📒 Files selected for processing (4)
  • AGENTS.md (1 hunks)
  • apps/desktop/src/renderer/lib/shortcuts.ts (3 hunks)
  • apps/desktop/src/renderer/screens/main/components/MainContent/TabContent.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/MainContent/Terminal.tsx (3 hunks)
🔇 Additional comments (4)
apps/desktop/src/renderer/screens/main/components/MainContent/TabContent.tsx (1)

183-192: Terminal wiring for workspace/worktree IDs looks correct—confirm all call sites

Passing workspaceId and worktreeId through to Terminal aligns with how TerminalTabContent already uses them for CWD persistence and is consistent with the new close-terminal behavior.

Please double‑check other <Terminal> usages (if any outside this file) to ensure they either pass valid IDs or intentionally rely on the no‑op behavior when IDs are missing.

apps/desktop/src/renderer/lib/shortcuts.ts (1)

26-29: New terminal close handler and Meta+W shortcut look good—check interaction with tab close

Adding closeTerminal to ShortcutHandlers and wiring Meta+W in createTerminalShortcuts follows the existing shortcut patterns and keeps the API tidy.

Given that tab management already binds Meta+W to “Close current tab”, please confirm that when focus is inside the terminal:

  • Only the intended close behavior runs once (no double tab‑delete), and
  • Meta+W still closes terminal tabs even in any edge cases where workspaceId/worktreeId might be missing.

If needed, we can adjust event handling or fallback to tab‑level close to avoid swallowed keystrokes.

Also applies to: 182-208

apps/desktop/src/renderer/screens/main/components/MainContent/Terminal.tsx (2)

13-20: Props extension to carry workspace/worktree IDs into Terminal is straightforward

Making workspaceId and worktreeId optional props on Terminal and threading them through TerminalComponent matches how they’re computed in TabContent and keeps the surface area small.

Please confirm that Terminal isn’t used in contexts where these IDs are required but not provided; in those cases, close behavior will depend on higher‑level tab shortcuts instead of the new terminal‑level handler.

Also applies to: 75-82


185-212: closeTerminal shortcut IPC flow is reasonable—verify ID availability and lifecycle

The new closeTerminal handler correctly:

  • Checks terminalIdRef.current && workspaceId && worktreeId,
  • Calls tab-delete via ipcRenderer.invoke with { workspaceId, worktreeId, tabId: terminalIdRef.current }, and
  • Logs failures without throwing.

This is a clean, localized way to close the backing tab from within the terminal.

Two edge cases worth validating in practice:

  1. For any terminal tab, ensure workspaceId and worktreeId are always set so Meta+W actually closes it instead of becoming a no‑op that still consumes the shortcut.
  2. If a terminal/tab can ever be moved between workspaces/worktrees without changing terminalId, check that the captured IDs remain correct; if not, we may want to store them in refs and read from those inside closeTerminal.

Kitenite and others added 3 commits November 16, 2025 16:17
Changes Electron menu to use Cmd+Shift+W for closing windows (Arc-style),
freeing up Cmd+W for renderer-side shortcuts to close tabs/terminals.

**Changes:**
- menu.ts: Replace default close with custom Cmd+Shift+W handler
- Terminal.tsx: Enhance closeTerminal to dispatch workspace-changed event
- Sidebar.tsx: Listen for workspace-changed events to refresh UI
- AGENTS.md: Document new Window shortcuts section

This prevents Cmd+W from closing the window and ensures it properly
closes terminals without killing the shell process.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Refactored Cmd+W handling to work like VS Code - registers at window
level so it works from anywhere (sidebar, terminal, etc).

**Changes:**
- MainScreen.tsx: Add global keyboard shortcuts listener
  - Handles Cmd+W at window level for all tabs
  - Dispatches workspace-changed event after tab deletion
- Terminal.tsx: Simplified to only prevent Cmd+W from reaching shell
  - Removed IPC call handling (now done at window level)
  - Still prevents Cmd+W from being interpreted as Ctrl+W by shell
  - Kept Cmd+K for clear terminal

This matches VS Code behavior where shortcuts work regardless of focus.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Since Cmd+W handling moved to window level (MainScreen), Terminal
component no longer needs workspaceId/worktreeId props.

**Changes:**
- Terminal.tsx: Remove workspaceId and worktreeId from props interface
- TabContent.tsx: Remove workspaceId and worktreeId from Terminal usage

This follows the principle of using context providers instead of prop
drilling for shared state.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Kitenite Kitenite changed the title more hotkeys CMD+W to close tab Nov 17, 2025
@Kitenite
Kitenite merged commit 32f49b7 into main Nov 17, 2025
1 check passed
@Kitenite
Kitenite deleted the more-hotkeys-ju2l branch November 17, 2025 00:31
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.

1 participant