Skip to content
Merged
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 @@ -42,6 +42,10 @@ export const Terminal = ({ tabId, workspaceId }: TerminalProps) => {
? focusedPaneIds[pane.windowId] === paneId
: false;

// Ref to track focus state for use in terminal creation effect
const isFocusedRef = useRef(isFocused);
isFocusedRef.current = isFocused;

// Required for resolving relative file paths in terminal commands
const { data: workspaceCwd } =
trpc.terminal.getWorkspaceCwd.useQuery(workspaceId);
Expand Down Expand Up @@ -108,6 +112,13 @@ export const Terminal = ({ tabId, workspaceId }: TerminalProps) => {
}
}, [isFocused]);

// Autofocus terminal when it becomes the focused pane (e.g., after split)
useEffect(() => {
if (isFocused && xtermRef.current) {
xtermRef.current.focus();
}
}, [isFocused]);

// Toggle search with Cmd+F (only for the focused terminal)
useHotkeys(
HOTKEYS.FIND_IN_TERMINAL.keys,
Expand All @@ -133,6 +144,11 @@ export const Terminal = ({ tabId, workspaceId }: TerminalProps) => {
fitAddonRef.current = fitAddon;
isExitedRef.current = false;

// Autofocus on initial render if this terminal is the focused pane
if (isFocusedRef.current) {
xterm.focus();
}

// Load search addon for Cmd+F functionality
import("@xterm/addon-search").then(({ SearchAddon }) => {
if (isUnmounted) return;
Expand Down