Skip to content

Fix Cmd+K to clear terminal - #230

Merged
AviPeltz merged 1 commit into
mainfrom
fix/terminal-cmd-k-clear
Dec 2, 2025
Merged

AviPeltz merged 1 commit into
mainfrom
fix/terminal-cmd-k-clear

Conversation

@AviPeltz

@AviPeltz AviPeltz commented Dec 2, 2025 •

Copy link
Copy Markdown
Collaborator

Add CLEAR_TERMINAL hotkey (meta+k) and implement the keyboard handler to clear the terminal buffer when pressed.

🤖 Generated with Claude Code

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

  • New Features
    • Added Cmd+K keyboard shortcut to clear the terminal in the desktop application.

✏️ Tip: You can customize this high-level summary in your review settings.

Add CLEAR_TERMINAL hotkey (meta+k) and implement the keyboard handler
to clear the terminal buffer when pressed.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 2, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
website Ready Ready Preview Comment Dec 2, 2025 0:12am

@coderabbitai

coderabbitai Bot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR introduces a clear-terminal hotkey feature. It adds an onClear callback to the keyboard handler in the Terminal component, implements Cmd+K event detection in the helpers module, and registers the new CLEAR_TERMINAL hotkey definition in the global hotkeys mapping.

Changes

Cohort / File(s) Summary
Terminal keyboard handler implementation
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx, apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
Adds onClear?: () => void optional callback to KeyboardHandlerOptions interface; extends keyboard event handling to detect Cmd+K (metaKey + K) and invoke onClear on keydown with default prevention; updates JSDoc comments.
Hotkey definition
apps/desktop/src/shared/hotkeys.ts
Registers new CLEAR_TERMINAL hotkey entry with keys "meta+k", label "Clear Terminal", and category "Terminal".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

The changes follow established patterns across the codebase (similar to existing hotkey definitions and callback handlers), involve straightforward additions without complex business logic, and minimal scope across three files.

Possibly related PRs

Poem

🐰 With Cmd+K, the screen goes clean,
Terminal clears like it's never been,
A rabbit's shortcut, swift and keen,
The tidiest terminal ever seen! 🧹✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix Cmd+K to clear terminal' clearly and concisely describes the main change, directly reflecting the implementation of the Cmd+K hotkey for clearing the terminal buffer.
Description check ✅ Passed The description addresses the main purpose but leaves several template sections incomplete, including Related Issues, Testing details, Screenshots, and Additional Notes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 fix/terminal-cmd-k-clear

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 and usage tips.

@AviPeltz
AviPeltz merged commit e74886d into main Dec 2, 2025
6 of 7 checks passed

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a08498 and e13a516.

📒 Files selected for processing (3)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts (2 hunks)
  • apps/desktop/src/shared/hotkeys.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/desktop/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc

Files:

  • apps/desktop/src/shared/hotkeys.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: Please use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Files:

  • apps/desktop/src/shared/hotkeys.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Avoid using any type - use explicit types instead for type safety
Use camelCase for variable and function names following existing codebase patterns
Keep diffs minimal with targeted edits only - avoid unnecessary changes when making modifications
Follow existing patterns and match the codebase style when writing new code

Files:

  • apps/desktop/src/shared/hotkeys.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
apps/desktop/src/renderer/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules (fs, path, os, net, etc.) in renderer process code - browser environment only

Files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
**/components/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

**/components/**/*.tsx: Create one folder per component with structure: ComponentName/ComponentName.tsx + index.ts for barrel export
Co-locate tests next to the component file they test (e.g., ComponentName.test.tsx)
Co-locate dependencies (utils, hooks, constants, config, stories) next to the file using them
Use nested components/ subdirectory within a parent component only if a sub-component is used 2+ times within that parent; otherwise keep it in the parent's components/ folder
One component per file - avoid multi-component files

Files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
apps/desktop/src/renderer/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Call IPC methods using window.ipcRenderer.invoke() with object parameters - TypeScript will infer the exact response type automatically

Files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (3)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (1)

188-190: LGTM!

The onClear handler correctly invokes xterm.clear() to clear the terminal buffer when the hotkey is triggered.

apps/desktop/src/shared/hotkeys.ts (1)

116-120: LGTM!

The hotkey definition follows the established pattern and is correctly categorized under "Terminal".

apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts (1)

133-134: LGTM!

The onClear callback is properly typed and documented, following the existing pattern established by onShiftEnter.

Comment on lines +163 to +176
// Handle Cmd+K to clear terminal (handle directly since it needs xterm access)
const isClearShortcut =
event.key.toLowerCase() === "k" &&
event.metaKey &&
!event.shiftKey &&
!event.ctrlKey &&
!event.altKey;

if (isClearShortcut) {
if (event.type === "keydown" && options.onClear) {
options.onClear();
}
return false;
}

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.

⚠️ Potential issue | 🔴 Critical

Critical: Cross-platform compatibility issue - Ctrl+K won't work on Windows/Linux.

The clear shortcut detection only checks event.metaKey (Line 166), which is the Cmd key on Mac or the Windows key on Windows/Linux—not the Ctrl key. This means Ctrl+K won't trigger the clear functionality on Windows/Linux, even though the hotkey definition uses "meta+k" which per the comment in hotkeys.ts should map to "Cmd on Mac, Ctrl on Windows/Linux."

The check at Line 168 explicitly excludes event.ctrlKey, further preventing Ctrl+K from working.

Apply this diff to support both Cmd (Mac) and Ctrl (Windows/Linux):

 		// Handle Cmd+K to clear terminal (handle directly since it needs xterm access)
 		const isClearShortcut =
 			event.key.toLowerCase() === "k" &&
-			event.metaKey &&
+			(event.metaKey || event.ctrlKey) &&
 			!event.shiftKey &&
-			!event.ctrlKey &&
 			!event.altKey;

This aligns with the pattern at Line 179 where both metaKey and ctrlKey are treated as alternatives for cross-platform modifier key support.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Handle Cmd+K to clear terminal (handle directly since it needs xterm access)
const isClearShortcut =
event.key.toLowerCase() === "k" &&
event.metaKey &&
!event.shiftKey &&
!event.ctrlKey &&
!event.altKey;
if (isClearShortcut) {
if (event.type === "keydown" && options.onClear) {
options.onClear();
}
return false;
}
// Handle Cmd+K to clear terminal (handle directly since it needs xterm access)
const isClearShortcut =
event.key.toLowerCase() === "k" &&
(event.metaKey || event.ctrlKey) &&
!event.shiftKey &&
!event.altKey;
if (isClearShortcut) {
if (event.type === "keydown" && options.onClear) {
options.onClear();
}
return false;
}
🤖 Prompt for AI Agents
In
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
around lines 163 to 176, the clear-shortcut check currently only recognizes
event.metaKey and explicitly excludes event.ctrlKey, preventing Ctrl+K from
working on Windows/Linux; change the detection so the modifier is (event.metaKey
|| event.ctrlKey) and remove the exclusion of ctrlKey (keep excluding
shift/alt/other modifiers), so that isClearShortcut is true for either Cmd+K on
macOS or Ctrl+K on Windows/Linux, and preserve the existing behavior of calling
options.onClear() on keydown and returning false.

This branch was successfully deployed

1 active deployment
Preview — e13a516a Deployed Dec 2, 2025 by vercel[bot]
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