feat: add terminal keyboard shortcuts with cross-platform support

- Add splitTerminalRight, splitTerminalDown, closeTerminal to KeyboardShortcuts
- Wire up shortcuts in terminal view (Cmd+D, Cmd+Shift+D, Cmd+W on Mac)
- Auto-detect platform and use Ctrl instead of Cmd on Linux/Windows

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
SuperComboGamer
2025-12-13 01:28:58 -05:00
parent 11ddcfaf90
commit 2ebb650609
2 changed files with 66 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
"use client";
import React, { useState, useEffect, useCallback } from "react";
import React, { useState, useEffect, useCallback, useMemo } from "react";
import {
Terminal as TerminalIcon,
Plus,
@@ -15,6 +15,7 @@ import {
SquarePlus,
} from "lucide-react";
import { useAppStore, type TerminalPanelContent, type TerminalTab } from "@/store/app-store";
import { useKeyboardShortcutsConfig, type KeyboardShortcut } from "@/hooks/use-keyboard-shortcuts";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
@@ -338,6 +339,60 @@ export function TerminalView() {
}
};
// Get keyboard shortcuts config
const shortcuts = useKeyboardShortcutsConfig();
// Handle terminal-specific keyboard shortcuts
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
// Only handle shortcuts when terminal is unlocked and has an active session
if (!terminalState.isUnlocked || !terminalState.activeSessionId) return;
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
const cmdOrCtrl = isMac ? e.metaKey : e.ctrlKey;
// Parse shortcut string to check for match
const matchesShortcut = (shortcutStr: string) => {
const parts = shortcutStr.toLowerCase().split('+');
const key = parts[parts.length - 1];
const needsCmd = parts.includes('cmd');
const needsShift = parts.includes('shift');
const needsAlt = parts.includes('alt');
return (
e.key.toLowerCase() === key &&
cmdOrCtrl === needsCmd &&
e.shiftKey === needsShift &&
e.altKey === needsAlt
);
};
// Split terminal right (Cmd+D / Ctrl+D)
if (matchesShortcut(shortcuts.splitTerminalRight)) {
e.preventDefault();
createTerminal("horizontal", terminalState.activeSessionId);
return;
}
// Split terminal down (Cmd+Shift+D / Ctrl+Shift+D)
if (matchesShortcut(shortcuts.splitTerminalDown)) {
e.preventDefault();
createTerminal("vertical", terminalState.activeSessionId);
return;
}
// Close terminal (Cmd+W / Ctrl+W)
if (matchesShortcut(shortcuts.closeTerminal)) {
e.preventDefault();
killTerminal(terminalState.activeSessionId);
return;
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, [terminalState.isUnlocked, terminalState.activeSessionId, shortcuts]);
// Get a stable key for a panel
const getPanelKey = (panel: TerminalPanelContent): string => {
if (panel.type === "terminal") {

View File

@@ -160,6 +160,11 @@ export interface KeyboardShortcuts {
cyclePrevProject: string;
cycleNextProject: string;
addProfile: string;
// Terminal shortcuts
splitTerminalRight: string;
splitTerminalDown: string;
closeTerminal: string;
}
// Default keyboard shortcuts
@@ -188,6 +193,11 @@ export const DEFAULT_KEYBOARD_SHORTCUTS: KeyboardShortcuts = {
cyclePrevProject: "Q", // Global shortcut
cycleNextProject: "E", // Global shortcut
addProfile: "N", // Only active in profiles view
// Terminal shortcuts (only active in terminal view)
splitTerminalRight: "Cmd+D",
splitTerminalDown: "Cmd+Shift+D",
closeTerminal: "Cmd+W",
};
export interface ImageAttachment {