Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export const Terminal = ({ tabId, workspaceId }: TerminalProps) => {
writeRef.current({ tabId, data: "\\\n" });
}
},
onClear: () => {
xterm.clear();
},
});

const cleanupFocus = setupFocusListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,15 @@ export function createTerminalInstance(
export interface KeyboardHandlerOptions {
/** Callback for Shift+Enter to create a line continuation (like iTerm) */
onShiftEnter?: () => void;
/** Callback for Cmd+K to clear the terminal */
onClear?: () => void;
}

/**
* Setup keyboard handling for xterm including:
* - Shortcut forwarding: App hotkeys are re-dispatched to document for react-hotkeys-hook
* - Shift+Enter: Creates a line continuation (like iTerm) instead of executing
* - Cmd+K: Clears the terminal
*/
export function setupKeyboardHandler(
xterm: XTerm,
Expand All @@ -157,6 +160,21 @@ export function setupKeyboardHandler(
return false;
}

// 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;
}
Comment on lines +163 to +176

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.


if (event.type !== "keydown") return true;
if (!event.metaKey && !event.ctrlKey) return true;

Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/src/shared/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export const HOTKEYS = {
label: "Close Terminal",
category: "Terminal",
},
CLEAR_TERMINAL: {
keys: "meta+k",
label: "Clear Terminal",
category: "Terminal",
},
PREV_TERMINAL: {
keys: "meta+up",
label: "Previous Terminal",
Expand Down