Skip to content
Open
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
1 change: 1 addition & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4356,6 +4356,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
onCloseTerminal={closeTerminal}
onHeightChange={setTerminalHeight}
onAddTerminalContext={addTerminalContextToDraft}
keybindings={keybindings}
/>
);
})()}
Expand Down
35 changes: 33 additions & 2 deletions apps/web/src/components/ThreadTerminalDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FitAddon } from "@xterm/addon-fit";
import { Plus, SquareSplitHorizontal, TerminalSquare, Trash2, XIcon } from "lucide-react";
import { type ThreadId } from "@t3tools/contracts";
import { type ResolvedKeybindingsConfig, type ThreadId } from "@t3tools/contracts";
import { Terminal, type ITheme } from "@xterm/xterm";
import {
type PointerEvent as ReactPointerEvent,
Expand All @@ -19,7 +19,15 @@ import {
isTerminalLinkActivation,
resolvePathLinkTarget,
} from "../terminal-links";
import { isTerminalClearShortcut, terminalNavigationShortcutData } from "../keybindings";
import {
isDiffToggleShortcut,
isTerminalClearShortcut,
isTerminalCloseShortcut,
isTerminalNewShortcut,
isTerminalSplitShortcut,
isTerminalToggleShortcut,
terminalNavigationShortcutData,
} from "../keybindings";
import {
DEFAULT_THREAD_TERMINAL_HEIGHT,
DEFAULT_THREAD_TERMINAL_ID,
Expand Down Expand Up @@ -192,6 +200,7 @@ interface TerminalViewportProps {
autoFocus: boolean;
resizeEpoch: number;
drawerHeight: number;
keybindings: ResolvedKeybindingsConfig;
}

function TerminalViewport({
Expand All @@ -206,6 +215,7 @@ function TerminalViewport({
autoFocus,
resizeEpoch,
drawerHeight,
keybindings,
}: TerminalViewportProps) {
const containerRef = useRef<HTMLDivElement>(null);
const terminalRef = useRef<Terminal | null>(null);
Expand All @@ -220,6 +230,11 @@ function TerminalViewport({
const selectionActionOpenRef = useRef(false);
const selectionActionTimerRef = useRef<number | null>(null);

const keybindingsRef = useRef(keybindings);
useEffect(() => {
keybindingsRef.current = keybindings;
}, [keybindings]);

useEffect(() => {
onSessionExitedRef.current = onSessionExited;
}, [onSessionExited]);
Expand Down Expand Up @@ -343,6 +358,18 @@ function TerminalViewport({
};

terminal.attachCustomKeyEventHandler((event) => {
const currentKeybindings = keybindingsRef.current;
const options = { context: { terminalFocus: true, terminalOpen: true } };
if (
isTerminalToggleShortcut(event, currentKeybindings, options) ||
isTerminalSplitShortcut(event, currentKeybindings, options) ||
isTerminalNewShortcut(event, currentKeybindings, options) ||
isTerminalCloseShortcut(event, currentKeybindings, options) ||
isDiffToggleShortcut(event, currentKeybindings, options)
) {
return false;
}

const navigationData = terminalNavigationShortcutData(event);
if (navigationData !== null) {
event.preventDefault();
Expand Down Expand Up @@ -662,6 +689,7 @@ interface ThreadTerminalDrawerProps {
onCloseTerminal: (terminalId: string) => void;
onHeightChange: (height: number) => void;
onAddTerminalContext: (selection: TerminalContextSelection) => void;
keybindings: ResolvedKeybindingsConfig;
}

interface TerminalActionButtonProps {
Expand Down Expand Up @@ -712,6 +740,7 @@ export default function ThreadTerminalDrawer({
onCloseTerminal,
onHeightChange,
onAddTerminalContext,
keybindings,
}: ThreadTerminalDrawerProps) {
const [drawerHeight, setDrawerHeight] = useState(() => clampDrawerHeight(height));
const [resizeEpoch, setResizeEpoch] = useState(0);
Expand Down Expand Up @@ -1017,6 +1046,7 @@ export default function ThreadTerminalDrawer({
autoFocus={terminalId === resolvedActiveTerminalId}
resizeEpoch={resizeEpoch}
drawerHeight={drawerHeight}
keybindings={keybindings}
/>
</div>
</div>
Expand All @@ -1037,6 +1067,7 @@ export default function ThreadTerminalDrawer({
autoFocus
resizeEpoch={resizeEpoch}
drawerHeight={drawerHeight}
keybindings={keybindings}
/>
</div>
)}
Expand Down
Loading