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
5 changes: 5 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
type ProjectId,
type ProviderApprovalDecision,
type ServerProvider,
type ResolvedKeybindingsConfig,
type ScopedThreadRef,
type ThreadId,
type TurnId,
Expand Down Expand Up @@ -415,6 +416,7 @@
splitShortcutLabel: string | undefined;
newShortcutLabel: string | undefined;
closeShortcutLabel: string | undefined;
keybindings: ResolvedKeybindingsConfig;
onAddTerminalContext: (selection: TerminalContextSelection) => void;
}

Expand All @@ -427,6 +429,7 @@
splitShortcutLabel,
newShortcutLabel,
closeShortcutLabel,
keybindings,
onAddTerminalContext,
}: PersistentThreadTerminalDrawerProps) {
const serverThread = useStore(useMemo(() => createThreadSelectorByRef(threadRef), [threadRef]));
Expand Down Expand Up @@ -570,6 +573,7 @@
splitShortcutLabel={visible ? splitShortcutLabel : undefined}
newShortcutLabel={visible ? newShortcutLabel : undefined}
closeShortcutLabel={visible ? closeShortcutLabel : undefined}
keybindings={keybindings}
onActiveTerminalChange={activateTerminal}
onCloseTerminal={closeTerminal}
onHeightChange={setTerminalHeight}
Expand Down Expand Up @@ -1552,7 +1556,7 @@
);

const focusComposer = useCallback(() => {
composerRef.current?.focusAtEnd();

Check warning on line 1559 in apps/web/src/components/ChatView.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

eslint-plugin-react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'composerRef.current'
}, []);
const scheduleComposerFocus = useCallback(() => {
window.requestAnimationFrame(() => {
Expand All @@ -1560,7 +1564,7 @@
});
}, [focusComposer]);
const addTerminalContextToDraft = useCallback((selection: TerminalContextSelection) => {
composerRef.current?.addTerminalContext(selection);

Check warning on line 1567 in apps/web/src/components/ChatView.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

eslint-plugin-react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'composerRef.current'
}, []);
const setTerminalOpen = useCallback(
(open: boolean) => {
Expand Down Expand Up @@ -2757,7 +2761,7 @@
};
});
promptRef.current = "";
composerRef.current?.resetCursorState({ cursor: 0 });

Check warning on line 2764 in apps/web/src/components/ChatView.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

eslint-plugin-react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'composerRef.current'
},
[activePendingProgress?.activeQuestion, activePendingUserInput],
);
Expand All @@ -2784,7 +2788,7 @@
),
},
}));
const snapshot = composerRef.current?.readSnapshot();

Check warning on line 2791 in apps/web/src/components/ChatView.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

eslint-plugin-react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'composerRef.current'
if (
snapshot?.value !== value ||
snapshot.cursor !== nextCursor ||
Expand Down Expand Up @@ -2847,7 +2851,7 @@
return;
}

const sendCtx = composerRef.current?.getSendContext();

Check warning on line 2854 in apps/web/src/components/ChatView.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

eslint-plugin-react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'composerRef.current'
if (!sendCtx) {
return;
}
Expand Down Expand Up @@ -2982,7 +2986,7 @@
return;
}

const sendCtx = composerRef.current?.getSendContext();

Check warning on line 2989 in apps/web/src/components/ChatView.tsx

View workflow job for this annotation

GitHub Actions / Format, Lint, Typecheck, Test, Browser Test, Build

eslint-plugin-react-hooks(exhaustive-deps)

React Hook useCallback has a missing dependency: 'composerRef.current'
if (!sendCtx) {
return;
}
Expand Down Expand Up @@ -3443,6 +3447,7 @@
splitShortcutLabel={splitTerminalShortcutLabel ?? undefined}
newShortcutLabel={newTerminalShortcutLabel ?? undefined}
closeShortcutLabel={closeTerminalShortcutLabel ?? undefined}
keybindings={keybindings}
onAddTerminalContext={addTerminalContextToDraft}
/>
))}
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/ThreadTerminalDrawer.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ async function mountTerminalViewport(props: {
autoFocus={false}
resizeEpoch={0}
drawerHeight={320}
keybindings={[]}
/>,
{ container: host },
);
Expand All @@ -196,6 +197,7 @@ async function mountTerminalViewport(props: {
autoFocus={false}
resizeEpoch={0}
drawerHeight={320}
keybindings={[]}
/>,
);
},
Expand Down
29 changes: 29 additions & 0 deletions apps/web/src/components/ThreadTerminalDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FitAddon } from "@xterm/addon-fit";
import { Plus, SquareSplitHorizontal, TerminalSquare, Trash2, XIcon } from "lucide-react";
import {
type ResolvedKeybindingsConfig,
type ScopedThreadRef,
type TerminalEvent,
type TerminalSessionSnapshot,
Expand Down Expand Up @@ -29,7 +30,12 @@ import {
wrappedTerminalLinkRangeIntersectsBufferLine,
} from "../terminal-links";
import {
isDiffToggleShortcut,
isTerminalClearShortcut,
isTerminalCloseShortcut,
isTerminalNewShortcut,
isTerminalSplitShortcut,
isTerminalToggleShortcut,
terminalDeleteShortcutData,
terminalNavigationShortcutData,
} from "../keybindings";
Expand Down Expand Up @@ -255,6 +261,7 @@ interface TerminalViewportProps {
autoFocus: boolean;
resizeEpoch: number;
drawerHeight: number;
keybindings: ResolvedKeybindingsConfig;
}

export function TerminalViewport({
Expand All @@ -271,6 +278,7 @@ export function TerminalViewport({
autoFocus,
resizeEpoch,
drawerHeight,
keybindings,
}: TerminalViewportProps) {
const containerRef = useRef<HTMLDivElement>(null);
const terminalRef = useRef<Terminal | null>(null);
Expand All @@ -282,6 +290,7 @@ export function TerminalViewport({
const selectionActionRequestIdRef = useRef(0);
const selectionActionOpenRef = useRef(false);
const selectionActionTimerRef = useRef<number | null>(null);
const keybindingsRef = useRef(keybindings);
const lastAppliedTerminalEventIdRef = useRef(0);
const terminalHydratedRef = useRef(false);
const handleSessionExited = useEffectEvent(() => {
Expand All @@ -292,6 +301,10 @@ export function TerminalViewport({
});
const readTerminalLabel = useEffectEvent(() => terminalLabel);

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

useEffect(() => {
const mount = containerRef.current;
if (!mount) return;
Expand Down Expand Up @@ -403,6 +416,18 @@ export 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 @@ -795,6 +820,7 @@ interface ThreadTerminalDrawerProps {
onCloseTerminal: (terminalId: string) => void;
onHeightChange: (height: number) => void;
onAddTerminalContext: (selection: TerminalContextSelection) => void;
keybindings: ResolvedKeybindingsConfig;
}

interface TerminalActionButtonProps {
Expand Down Expand Up @@ -848,6 +874,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 @@ -1166,6 +1193,7 @@ export default function ThreadTerminalDrawer({
autoFocus={terminalId === resolvedActiveTerminalId}
resizeEpoch={resizeEpoch}
drawerHeight={drawerHeight}
keybindings={keybindings}
/>
</div>
</div>
Expand All @@ -1188,6 +1216,7 @@ export default function ThreadTerminalDrawer({
autoFocus
resizeEpoch={resizeEpoch}
drawerHeight={drawerHeight}
keybindings={keybindings}
/>
</div>
)}
Expand Down
Loading