Add shortcuts for terminal close and chat with same Git state #56
main fromcodething/48203257·merged by juliusmarminge View on GitHubSummary#
- add new keybinding commands:
terminal.closeandchat.newSameGitStatein shared contracts - register default shortcuts for those commands (
mod+wfor terminal close withterminalFocus,mod+shift+nfor new chat with same Git state) - wire UI handling so
terminal.closecloses the active terminal fromChatView - update sidebar new-chat flow to optionally preserve
branchandworktreePathwhen usingchat.newSameGitState - extend docs and tests across server, web, and contracts for the new commands and shortcut behavior
Testing#
packages/contracts/src/keybindings.test.ts: validatesterminal.closeis accepted by schema parsingapps/server/src/keybindings.test.ts: verifies default bindings includeterminal.closeandchat.newSameGitStateapps/web/src/keybindings.test.ts: verifies shortcut matching forterminal.closeandchat.newSameGitState, includingterminalFocusbehavior- Not run: full project lint/test commands in this environment
Summary by CodeRabbit#
Release Notes#
New Features
- Added keyboard shortcut (Mod+W) to close the active terminal.
- Added keyboard shortcut (Mod+Shift+N) to create a new chat thread with the current branch/worktree state.
- Terminal and chat actions are now context-aware, responding intelligently based on terminal focus state.
UI/UX Improvements
- Enhanced terminal close action visibility in the terminal drawer with clearer labeling and icon.
- 1
Add mod+w terminal close and gate chat thread creation shortcuts to preserve or clear Git context in server defaults and web UI#
Update default keybindings to include
terminal.closeonmod+wunderterminalFocusand addchat.new/chat.newLocalgated by!terminalFocus; wireterminal.closehandling and shortcut labels inChatViewandThreadTerminalDrawer; routechat.newto preserve active thread branch/worktree andchat.newLocalto create a local thread inSidebar; extend keybinding schema and tests.📍Where to Start#
Start with the updated default bindings in keybindings.ts, then review shortcut handling in ChatView.tsx and thread creation logic in Sidebar.tsx.
Macroscope summarized 9075086.Greptile Summary
Adds two new keybinding commands (
terminal.closeandchat.newSameGitState) with default shortcuts (mod+wandmod+shift+n), wires them into the web UI, and updates docs/tests across all three packages.- Extends the shared
keybindingCommandSchemaenum inpackages/contractswith the two new commands - Registers default bindings in
apps/server/src/keybindings.ts—terminal.closeis gated byterminalFocus - Adds shortcut matcher functions (
isTerminalCloseShortcut,isChatNewSameGitStateShortcut) in the web keybindings module ChatViewhandlesterminal.closeby closing the active terminal viacloseTerminal, with proper dependency array updatesSidebarhandleschat.newSameGitStateby passing the active thread'sbranchandworktreePathtohandleNewThreadKEYBINDINGS.mdupdated with new commands and defaults- Tests added/updated across contracts, server, and web packages
- Note:
mod+wdefault may conflict with browser tab-close in non-Electron contexts (see inline comment)
Confidence Score: 4/5
- This PR is safe to merge with minor consideration around the mod+w browser shortcut conflict.
- The changes follow established patterns consistently across all three packages (contracts, server, web). The terminal close logic is properly guarded by
terminalFocuscontext and the store'scloseThreadTerminalhandles edge cases (last terminal gracefully resets to default). The new git-state-preserving thread creation is clean and well-integrated. The only concern is themod+wdefault potentially conflicting with browser tab-close behavior outside Electron, which is a UX consideration rather than a correctness bug. apps/web/src/components/ChatView.tsx— verify thatmod+wshortcut interception works as expected in browser-served mode (not just Electron).
Important Files Changed
Filename Overview packages/contracts/src/keybindings.ts Adds terminal.closeandchat.newSameGitStateto the keybinding command enum. Straightforward schema extension, no issues.apps/server/src/keybindings.ts Adds default keybinding rules for terminal.close(mod+w with terminalFocus) andchat.newSameGitState(mod+shift+n). Consistent with existing patterns.apps/web/src/keybindings.ts Adds isTerminalCloseShortcutandisChatNewSameGitStateShortcuthelper functions following existing pattern of delegating tomatchesCommandShortcut. No issues.apps/web/src/components/ChatView.tsx Wires terminal.closeshortcut to close the active terminal. Properly guards withterminalOpencheck, addsactiveTerminalIdandcloseTerminalto useEffect deps. Note:mod+wmay conflict with browser tab-close behavior in non-Electron contexts.apps/web/src/components/Sidebar.tsx Extends handleNewThreadto accept optional branch/worktreePath. Addschat.newSameGitStateshortcut handler that preserves active thread's git state. ChecksisChatNewSameGitStateShortcutbeforeisChatNewShortcut(correct order since they use different keys).apps/web/src/keybindings.test.ts Adds tests for terminal.closeandchat.newSameGitStateshortcut matching including terminalFocus context validation. Comprehensive coverage.apps/server/src/keybindings.test.ts Verifies new default keybinding entries exist for terminal.closeandchat.newSameGitState. Clean.packages/contracts/src/keybindings.test.ts Adds schema parsing test for terminal.closecommand. Clean extension of existing tests.KEYBINDINGS.md Documents new commands and their default keybindings. Accurate and consistent with code. Flowchart
Last reviewed commit: fb4afcaflowchart TD subgraph Contracts["packages/contracts"] Schema["keybindingCommandSchema\n+ terminal.close\n+ chat.newSameGitState"] end subgraph Server["apps/server"] Defaults["DEFAULT_KEYBINDINGS\nmod+w → terminal.close\nmod+shift+n → chat.newSameGitState"] end subgraph Web["apps/web"] Matchers["keybindings.ts\nisTerminalCloseShortcut()\nisChatNewSameGitStateShortcut()"] subgraph ChatView["ChatView.tsx"] KDHandler["keydown handler"] CloseCheck{"isTerminalCloseShortcut?"} CloseGuard{"terminalOpen?"} CloseAction["closeTerminal(activeTerminalId)"] end subgraph Sidebar["Sidebar.tsx"] SidebarHandler["keydown handler"] GitStateCheck{"isChatNewSameGitStateShortcut?"} NewThread["handleNewThread(projectId,\n{branch, worktreePath})"] end end Schema --> Defaults Defaults --> Matchers Matchers --> KDHandler KDHandler --> CloseCheck CloseCheck -->|Yes| CloseGuard CloseGuard -->|Yes| CloseAction Matchers --> SidebarHandler SidebarHandler --> GitStateCheck GitStateCheck -->|Yes| NewThread- Extends the shared
- 9 files reviewed, 1 comment [Edit Code Review Agent Settings](https://app.greptile.com/review/github) | [Greptile](https://greptile.com?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews)@@ -28,3 +28,4 @@2828 { key: "mod+j", command: "terminal.toggle" },2929 { key: "mod+d", command: "terminal.split", when: "terminalFocus" },3030 { key: "mod+n", command: "terminal.new", when: "terminalFocus" },31+ { key: "mod+w", command: "terminal.close", when: "terminalFocus" },
mod+wconflicts with browser tab-closeCmd+W/Ctrl+Wis the standard shortcut for closing a browser tab. While theterminalFocusguard limits when this fires, most browsers do not allow JavaScript to intercept andpreventDefault()onCtrl+W/Cmd+W— the tab will still close.This should work fine in Electron (where the app controls key event routing), but in the browser-served mode the shortcut will effectively be unusable and may cause unexpected tab closures. If the app is meant to run in both contexts, consider choosing a different default binding for browser users (e.g.
mod+shift+w). 🧹 Nitpick comments (1)
packages/contracts/src/keybindings.test.ts (1)
17-23: Consider adding chat.newSameGitState parsing coverage for parity.The new command is now part of the schema; adding a matching parse assertion keeps the contract tests symmetrical.
🧪 Suggested test addition
const parsedClose = keybindingRuleSchema.parse({ key: "mod+w", command: "terminal.close", }); assert.strictEqual(parsedClose.command, "terminal.close"); + + const parsedSameGit = keybindingRuleSchema.parse({ + key: "mod+shift+n", + command: "chat.newSameGitState", + }); + assert.strictEqual(parsedSameGit.command, "chat.newSameGitState");juliusmarminge merged this228862a
juliusmarminge closed this
Sign in to join this conversation.
Caution
Review failed#
The pull request is closed.
Walkthrough#
This pull request adds two new keybindings: a terminal close command (mod+w) that works when terminal focus is active, and a local chat thread command (mod+shift+n) that creates new threads while preserving the current git branch and worktree state. The changes update keybinding definitions, add context-aware shortcut detection helpers, and modify UI components to handle and display these new shortcuts.
Changes#
KEYBINDINGS.md,apps/server/src/keybindings.ts,packages/contracts/src/keybindings.tsterminal.close(mod+w) withterminalFocuscondition andchat.newLocal(mod+shift+n) with!terminalFocuscondition. Updated terminal and chat command semantics to be gated by focus state. Extended keybinding schema to include new command types.apps/web/src/keybindings.ts,apps/web/src/keybindings.test.ts,packages/contracts/src/keybindings.test.tsisTerminalCloseShortcut()andisChatNewLocalShortcut()helper functions following existing patterns. Extended test coverage to validate new shortcuts across platform-specific key combinations and focus states.apps/web/src/components/ChatView.tsxcloseTerminal(). Introduced memoizedcloseShortcutLabelfor display viaThreadTerminalDrawerprop. Extended keyboard handler dependencies.apps/web/src/components/Sidebar.tsxhandleNewThread()signature to accept optionalbranchandworktreePathparameters. Added keyboard handler forisChatNewLocalShortcutthat creates new threads while preserving current thread's git state.apps/web/src/components/ThreadTerminalDrawer.tsxcloseShortcutLabelprop. Introduced computedcloseTerminalActionLabelfor consistent labeling. Replaced plain close button (×) with Popover-based control displaying close tooltip with shortcut hint. Updated per-terminal close labels to include shortcut information.Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (3 passed)
main✨ Finishing touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.