Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): docked terminal launch + shift-key handling (#2008)

serafin-garcia62938e9514a6
diff --git a/.changeset/terminal-folder-launch-and-shift-keys.md b/.changeset/terminal-folder-launch-and-shift-keys.md
new file mode 100644
index 000000000..83d3b782c
--- /dev/null
+++ b/.changeset/terminal-folder-launch-and-shift-keys.md
@@ -0,0 +1,10 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Fix docked-terminal behavior in OK Desktop and add Shift+Enter newline support.
+
+- **The docked terminal is available in every view and survives navigation.** It now opens from folder, asset, and large-file views (previously it only mounted on the document editor and empty state, so "Open with AI → Claude" or ⌘J did nothing there). A single terminal is docked in the editor column — beside the doc/properties panel, which keeps its full height — and the session stays alive across tab switches, view-kind changes, and tab closes, instead of resetting each time.
+- **The terminal can be resized much taller.** Drag it up to 95% of the dock height for long CLI sessions (it was capped at 50%).
+- **Shift+Tab stays in the terminal.** It previously moved focus out of the terminal instead of reaching the running CLI (e.g. the Claude TUI's mode toggle); the keystroke now reaches the PTY.
+- **Shift+Enter inserts a newline** instead of submitting, matching how Ghostty and Cursor map the chord.
diff --git a/packages/app/src/components/EditorArea.dom.test.tsx b/packages/app/src/components/EditorArea.dom.test.tsx
index 487faa681..d8365fdde 100644
--- a/packages/app/src/components/EditorArea.dom.test.tsx
+++ b/packages/app/src/components/EditorArea.dom.test.tsx
@@ -1,6 +1,6 @@
-import { beforeEach, describe, expect, mock, test } from 'bun:test';
+import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
import { act, cleanup, render, screen } from '@testing-library/react';
-import type { ReactNode } from 'react';
+import { type ReactNode, useEffect } from 'react';
type SettingsDialogShellProps = {
open: boolean;
@@ -39,7 +39,29 @@ const EMPTY_DOC_CTX = {
docPanelAgentId: null,
docPanelExpandSignal: 0,
};
-let docCtx: typeof FOLDER_DOC_CTX | typeof EMPTY_DOC_CTX = FOLDER_DOC_CTX;
+const LARGE_FILE_DOC_CTX = {
+ activeDocName: 'big',
+ activeProvider: null,
+ activeTarget: { kind: 'large-file', docName: 'big', size: 9_999_999, limit: 1_000_000 },
+ recycleDocument: () => {},
+ docPanelMode: 'timeline',
+ docPanelAgentId: null,
+ docPanelExpandSignal: 0,
+};
+const ASSET_DOC_CTX = {
+ activeDocName: null,
+ activeProvider: null,
+ activeTarget: { kind: 'asset', assetPath: 'images/diagram.png', mediaKind: 'image' },
+ recycleDocument: () => {},
+ docPanelMode: 'timeline',
+ docPanelAgentId: null,
+ docPanelExpandSignal: 0,
+};
+let docCtx:
+ | typeof FOLDER_DOC_CTX
+ | typeof EMPTY_DOC_CTX
+ | typeof LARGE_FILE_DOC_CTX
+ | typeof ASSET_DOC_CTX = FOLDER_DOC_CTX;
mock.module('@/editor/DocumentContext', () => ({
useDocumentContext: () => docCtx,
useDocumentTransition: () => ({ openDocumentTransition: null }),
@@ -51,12 +73,22 @@ mock.module('@/components/EmptyEditorState', () => ({
),
}));
+let terminalDockMounts = 0;
+mock.module('@/components/EditorSkeleton', () => ({
+ EditorSkeleton: () => <div data-testid="editor-skeleton" />,
+}));
+
mock.module('./TerminalDock', () => ({
- TerminalDock: ({ children, visible }: { children: ReactNode; visible?: boolean }) => (
- <div data-testid="terminal-dock" data-visible={String(visible)}>
- {children}
- </div>
- ),
+ TerminalDock: ({ children, visible }: { children: ReactNode; visible?: boolean }) => {
+ useEffect(() => {
+ terminalDockMounts += 1;
+ }, []);
+ return (
+ <div data-testid="terminal-dock" data-visible={String(visible)}>
+ {children}
+ </div>
+ );
+ },
}));
mock.module('react-resizable-panels', () => ({
@@ -68,6 +100,14 @@ mock.module('react-resizable-panels', () => ({
}),
}));
+mock.module('@/components/ui/resizable', () => ({
+ ResizablePanelGroup: ({ children }: { children: ReactNode }) => (
+ <div data-testid="resizable-group">{children}</div>
+ ),
+ ResizablePanel: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+ ResizableHandle: () => <div data-testid="resizable-handle" />,
+}));
+
mock.module('@/hooks/use-doc-panel-layout', () => ({
useDocPanelLayout: () => ({ layout: 'panel', autoCollapse: false }),
}));
@@ -90,6 +130,18 @@ mock.module('@/components/FolderOverview', () => ({
),
}));
+mock.module('@/components/AssetPreview', () => ({
+ AssetPreview: ({ assetPath }: { assetPath: string }) => (
+ <div data-testid="asset-preview">{assetPath}</div>
+ ),
+}));
+
+mock.module('@/components/LargeFileEditorState', () => ({
+ LargeFileEditorState: ({ docName }: { docName: string }) => (
+ <div data-testid="large-file-state">{docName}</div>
+ ),
+}));
+
mock.module('@/components/settings/SettingsDialogShell', () => ({
SettingsDialogShell: (props: SettingsDialogShellProps) => {
shellProps.push(props);
@@ -186,3 +238,173 @@ describe('EditorArea empty-state terminal host', () => {
expect(screen.getByTestId('empty-editor-state')).toBeTruthy();
});
});
+
+describe('EditorArea folder-view terminal host', () => {
+ beforeEach(() => {
+ cleanup();
+ docCtx = FOLDER_DOC_CTX;
+ });
+
+ test('hosts the docked terminal in folder view when a terminal bridge is present', () => {
+ render(
+ <EditorArea
+ editorMode="wysiwyg"
+ onModeChange={() => {}}
+ activeTab="timeline"
+ onActiveTabChange={() => {}}
+ terminalBridge={{} as never}
+ terminalVisible
+ onTerminalVisibleChange={() => {}}
+ terminalLaunch={null}
+ />,
+ );
+
+ const dock = screen.getByTestId('terminal-dock');
+ expect(dock.getAttribute('data-visible')).toBe('true');
+ expect(dock.querySelector('[data-testid="folder-overview"]')).not.toBeNull();
+ });
+
+ test('renders the folder view with no terminal dock on the web host (no bridge)', () => {
+ renderEditorArea();
+
+ expect(screen.queryByTestId('terminal-dock')).toBeNull();
+ expect(screen.getByTestId('folder-overview').textContent).toBe('folder');
+ });
+});
+
+describe('EditorArea large-file-view terminal host', () => {
+ beforeEach(() => {
+ cleanup();
+ docCtx = LARGE_FILE_DOC_CTX;
+ });
+
+ test('hosts the docked terminal in the large-file view when a bridge is present', () => {
+ render(
+ <EditorArea
+ editorMode="wysiwyg"
+ onModeChange={() => {}}
+ activeTab="timeline"
+ onActiveTabChange={() => {}}
+ terminalBridge={{} as never}
+ terminalVisible
+ onTerminalVisibleChange={() => {}}
+ terminalLaunch={null}
+ />,
+ );
+
+ const dock = screen.getByTestId('terminal-dock');
+ expect(dock.getAttribute('data-visible')).toBe('true');
+ expect(dock.querySelector('[data-testid="large-file-state"]')).not.toBeNull();
+ });
+
+ test('renders the large-file view with no terminal dock on the web host (no bridge)', () => {
+ renderEditorArea();
+
+ expect(screen.queryByTestId('terminal-dock')).toBeNull();
+ expect(screen.getByTestId('large-file-state')).toBeTruthy();
+ });
+});
+
+describe('EditorArea asset-view terminal host', () => {
+ beforeEach(() => {
+ cleanup();
+ docCtx = ASSET_DOC_CTX;
+ });
+
+ test('hosts the docked terminal in the asset view when a bridge is present', () => {
+ render(
+ <EditorArea
+ editorMode="wysiwyg"
+ onModeChange={() => {}}
+ activeTab="timeline"
+ onActiveTabChange={() => {}}
+ terminalBridge={{} as never}
+ terminalVisible
+ onTerminalVisibleChange={() => {}}
+ terminalLaunch={null}
+ />,
+ );
+
+ const dock = screen.getByTestId('terminal-dock');
+ expect(dock.getAttribute('data-visible')).toBe('true');
+ expect(dock.querySelector('[data-testid="asset-preview"]')).not.toBeNull();
+ });
+
+ test('renders the asset view with no terminal dock on the web host (no bridge)', () => {
+ renderEditorArea();
+
+ expect(screen.queryByTestId('terminal-dock')).toBeNull();
+ expect(screen.getByTestId('asset-preview')).toBeTruthy();
+ });
+});
+
+describe('EditorArea terminal persists across view-kind switches', () => {
+ beforeEach(() => {
+ cleanup();
+ terminalDockMounts = 0;
+ docCtx = FOLDER_DOC_CTX;
+ });
+
+ test('keeps a single TerminalDock instance mounted while the active view kind changes', () => {
+ const props = {
+ editorMode: 'wysiwyg' as const,
+ onModeChange: () => {},
+ activeTab: 'timeline' as const,
+ onActiveTabChange: () => {},
+ terminalBridge: {} as never,
+ terminalVisible: true,
+ onTerminalVisibleChange: () => {},
+ terminalLaunch: null,
+ };
+ const { rerender } = render(<EditorArea {...props} />);
+ const mountsAfterInitial = terminalDockMounts;
+ expect(mountsAfterInitial).toBeGreaterThan(0);
+ expect(
+ screen.getByTestId('terminal-dock').querySelector('[data-testid="folder-overview"]'),
+ ).not.toBeNull();
+
+ docCtx = ASSET_DOC_CTX;
+ rerender(<EditorArea {...props} />);
+ expect(
+ screen.getByTestId('terminal-dock').querySelector('[data-testid="asset-preview"]'),
+ ).not.toBeNull();
+
+ docCtx = LARGE_FILE_DOC_CTX;
+ rerender(<EditorArea {...props} />);
+ expect(
+ screen.getByTestId('terminal-dock').querySelector('[data-testid="large-file-state"]'),
+ ).not.toBeNull();
+
+ expect(terminalDockMounts).toBe(mountsAfterInitial);
+ });
+});
+
+describe('EditorArea hash-load skeleton renders outside the panel group', () => {
+ beforeEach(() => {
+ cleanup();
+ docCtx = EMPTY_DOC_CTX;
+ });
+ afterEach(() => {
+ window.location.hash = '';
+ });
+
+ test('renders the load skeleton directly, not inside the terminal dock or panel group', () => {
+ window.location.hash = '#/some-doc';
+ render(
+ <EditorArea
+ editorMode="wysiwyg"
+ onModeChange={() => {}}
+ activeTab="timeline"
+ onActiveTabChange={() => {}}
+ terminalBridge={{} as never}
+ terminalVisible
+ onTerminalVisibleChange={() => {}}
+ terminalLaunch={null}
+ />,
+ );
+
+ expect(screen.getByTestId('editor-skeleton')).toBeTruthy();
+ expect(screen.queryByTestId('resizable-group')).toBeNull();
+ expect(screen.queryByTestId('terminal-dock')).toBeNull();
+ });
+});
diff --git a/packages/app/src/components/EditorArea.tsx b/packages/app/src/components/EditorArea.tsx
index 892da48ca..18ac48643 100644
--- a/packages/app/src/components/EditorArea.tsx
+++ b/packages/app/src/components/EditorArea.tsx
@@ -2,6 +2,7 @@ import { detectEmbeddedHostFromBrowser } from '@inkeep/open-knowledge-core';
import { Trans, useLingui } from '@lingui/react/macro';
import {
lazy,
+ type ReactNode,
Suspense,
useDeferredValue,
useEffect,
@@ -302,8 +303,11 @@ function EditorAreaInner({
}
}
+ let viewContent: ReactNode;
+ let rightPanel: ReactNode = null;
+
if (activeTarget?.kind === 'large-file') {
- return (
+ viewContent = (
<LargeFileEditorState
docName={activeTarget.docName}
size={activeTarget.size}
@@ -313,22 +317,16 @@ function EditorAreaInner({
}
/>
);
- }
-
- if (activeTarget?.kind === 'folder') {
+ } else if (activeTarget?.kind === 'folder') {
+ viewContent = <FolderOverview folderPath={activeTarget.folderPath} />;
const showAgentPanel = docPanelMode === 'agent' && docPanelAgentId !== null;
- if (!showAgentPanel) {
- return <FolderOverview folderPath={activeTarget.folderPath} />;
- }
- return (
- <div className="flex min-h-0 flex-1">
- <ResizablePanelGroup orientation="horizontal">
- <ResizablePanel minSize="30%" defaultSize="75%">
- <FolderOverview folderPath={activeTarget.folderPath} />
- </ResizablePanel>
+ if (showAgentPanel) {
+ rightPanel = (
+ <>
<ResizableHandle withHandle />
{/* Non-collapsible — folder view has no toolbar toggle; dismiss via avatar re-click. */}
<ResizablePanel
+ id="agent-panel"
defaultSize="25%"
minSize="300px"
maxSize="40%"
@@ -348,55 +346,38 @@ function EditorAreaInner({
<LazyActivityModeContent showBackButton={false} />
</Suspense>
</ResizablePanel>
- </ResizablePanelGroup>
- </div>
- );
- }
-
- if (activeTarget?.kind === 'asset') {
- return (
+ </>
+ );
+ }
+ } else if (activeTarget?.kind === 'asset') {
+ viewContent = (
<AssetPreview
key={activeTarget.assetPath}
assetPath={activeTarget.assetPath}
mediaKind={activeTarget.mediaKind}
/>
);
- }
-
- if (!activeProvider || !activeDocName) {
+ } else if (!activeProvider || !activeDocName) {
const hashDoc = typeof window !== 'undefined' ? docNameFromHash(window.location.hash) : null;
if (hashDoc !== null) {
return <EditorSkeleton />;
}
- if (terminalBridge != null) {
- return (
- <TerminalDock
- bridge={terminalBridge}
- visible={terminalVisible}
- onVisibleChange={onTerminalVisibleChange ?? (() => {})}
- launch={terminalLaunch}
- >
- <EmptyEditorState terminalVisible={terminalVisible} />
- </TerminalDock>
- );
- }
- return <EmptyEditorState />;
- }
-
- const isSourceMode = editorMode === 'source';
- const sourceDisabled = !isConnected;
+ viewContent = <EmptyEditorState terminalVisible={terminalVisible} />;
+ } else {
+ const isSourceMode = editorMode === 'source';
+ const sourceDisabled = !isConnected;
- const isPanelCollapsed = isCollapsed;
+ const isPanelCollapsed = isCollapsed;
- function openAddPropertyForm() {
- if (!activeDocName) return;
- requestAddProperty(activeDocName);
- }
+ function openAddPropertyForm() {
+ if (!activeDocName) return;
+ requestAddProperty(activeDocName);
+ }
- const editorContent = (
- <div className="relative flex h-full flex-col">
- <div className="relative min-h-0 flex-1">
- {/* Hybrid Activity + Suspense + ErrorBoundary render tree.
+ const editorContent = (
+ <div className="relative flex h-full flex-col">
+ <div className="relative min-h-0 flex-1">
+ {/* Hybrid Activity + Suspense + ErrorBoundary render tree.
EditorActivityPool keeps Tiptap eager and lazy-loads SourceEditor on
the first source-mode visit for each doc, then preserves the per-doc
display:none toggle after that initial load. Each Activity entry owns
@@ -408,17 +389,17 @@ function EditorAreaInner({
hidden doc's cached rejected syncPromise cannot re-throw into
the visible UI (QA-023/024). See EditorActivityPool.tsx file
docstring "ERROR + SUSPENSE SCOPING" for rationale. */}
- <div className="relative h-full">
- <EditorActivityPool
- activeDocName={deferredActiveDocName ?? activeDocName}
- isSourceMode={isSourceMode}
- editorPlaceholder={editorPlaceholder}
- previousDocName={previousDocName ?? undefined}
- onNavigateBack={navigateBackToDoc}
- onRecycle={recycleDocument}
- />
- <FindReplaceController activeDocName={activeDocName} isSourceMode={isSourceMode} />
- {/* Nav-pending skeleton overlay. Rendered when the urgent
+ <div className="relative h-full">
+ <EditorActivityPool
+ activeDocName={deferredActiveDocName ?? activeDocName}
+ isSourceMode={isSourceMode}
+ editorPlaceholder={editorPlaceholder}
+ previousDocName={previousDocName ?? undefined}
+ onNavigateBack={navigateBackToDoc}
+ onRecycle={recycleDocument}
+ />
+ <FindReplaceController activeDocName={activeDocName} isSourceMode={isSourceMode} />
+ {/* Nav-pending skeleton overlay. Rendered when the urgent
`activeDocName` (shell state — driving sidebar highlight +
header title) has moved past `deferredActiveDocName` (editor
subtree prop), AND the upcoming deferred commit will pay a
@@ -450,71 +431,43 @@ function EditorAreaInner({
(mount-promise.test.ts `mountPromiseHasResolved (warm-
reopen overlay gate)` + editor-cache.test.ts mount-
promise-cancellation describes). */}
- {shouldPaintOverlay({
- activeDocName,
- deferredActiveDocName,
- mountResolved: activeDocName !== null && mountPromiseHasResolved(activeDocName),
- syncResolved: activeDocName !== null && syncPromiseHasResolved(activeDocName),
- }) ? (
- <div className="absolute inset-0 z-10 bg-background">
- <EditorSkeleton />
- {/* Mount-stalled affordance — surfaces a "Cancel" link
+ {shouldPaintOverlay({
+ activeDocName,
+ deferredActiveDocName,
+ mountResolved: activeDocName !== null && mountPromiseHasResolved(activeDocName),
+ syncResolved: activeDocName !== null && syncPromiseHasResolved(activeDocName),
+ }) ? (
+ <div className="absolute inset-0 z-10 bg-background">
+ <EditorSkeleton />
+ {/* Mount-stalled affordance — surfaces a "Cancel" link
when the mount-promise substrate emits `ok/mount/stalled`
past MOUNT_STALLED_THRESHOLD_MS (10s default). Only
shown when the skeleton is already overlay-active, so a
fast mount never sees the affordance. */}
- {activeDocName !== null ? <MountStalledAffordance docName={activeDocName} /> : null}
- </div>
- ) : null}
+ {activeDocName !== null ? <MountStalledAffordance docName={activeDocName} /> : null}
+ </div>
+ ) : null}
+ </div>
+ {!isConflict && (
+ <EditorToolbar
+ activeDocName={activeDocName}
+ isSourceMode={isSourceMode}
+ sourceDisabled={sourceDisabled}
+ onModeChange={onModeChange}
+ showAddPropertyButton={!isSourceMode}
+ onAddProperty={openAddPropertyForm}
+ isPanelCollapsed={isPanelCollapsed}
+ onTogglePanel={togglePanel}
+ />
+ )}
</div>
- {!isConflict && (
- <EditorToolbar
- activeDocName={activeDocName}
- isSourceMode={isSourceMode}
- sourceDisabled={sourceDisabled}
- onModeChange={onModeChange}
- showAddPropertyButton={!isSourceMode}
- onAddProperty={openAddPropertyForm}
- isPanelCollapsed={isPanelCollapsed}
- onTogglePanel={togglePanel}
- />
- )}
+ <EditorFooter stats={stats} selectionStats={selectionStats} showStats={showStats} />
</div>
- <EditorFooter stats={stats} selectionStats={selectionStats} showStats={showStats} />
- </div>
- );
-
- const editorColumn =
- terminalBridge != null ? (
- <TerminalDock
- bridge={terminalBridge}
- visible={terminalVisible}
- onVisibleChange={onTerminalVisibleChange ?? (() => {})}
- launch={terminalLaunch}
- >
- {editorContent}
- </TerminalDock>
- ) : (
- editorContent
);
- return (
- <div className="flex min-h-0 flex-1" ref={setGroupContainerEl}>
- <ResizablePanelGroup
- orientation="horizontal"
- data-dragging={isDraggingDocHandle || undefined}
- >
- <ResizablePanel
- minSize="30%"
- {...(initialRightCollapsed ? { defaultSize: '100%' } : {})}
- className={
- isDraggingDocHandle
- ? undefined
- : 'transition-[flex-grow] duration-200 ease-out motion-reduce:transition-none motion-reduce:duration-0'
- }
- >
- {editorColumn}
- </ResizablePanel>
+ viewContent = editorContent;
+ rightPanel = (
+ <>
<ResizableHandle
withHandle
disabled={isEmbedded && isCollapsed}
@@ -559,6 +512,42 @@ function EditorAreaInner({
mode={docPanelMode}
/>
</ResizablePanel>
+ </>
+ );
+ }
+
+ const leftColumn =
+ terminalBridge != null ? (
+ <TerminalDock
+ bridge={terminalBridge}
+ visible={terminalVisible}
+ onVisibleChange={onTerminalVisibleChange ?? (() => {})}
+ launch={terminalLaunch}
+ >
+ {viewContent}
+ </TerminalDock>
+ ) : (
+ viewContent
+ );
+
+ return (
+ <div className="flex min-h-0 flex-1" ref={setGroupContainerEl}>
+ <ResizablePanelGroup
+ orientation="horizontal"
+ data-dragging={isDraggingDocHandle || undefined}
+ >
+ <ResizablePanel
+ minSize="30%"
+ {...(rightPanel != null && !initialRightCollapsed ? {} : { defaultSize: '100%' })}
+ className={
+ isDraggingDocHandle
+ ? undefined
+ : 'transition-[flex-grow] duration-200 ease-out motion-reduce:transition-none motion-reduce:duration-0'
+ }
+ >
+ {leftColumn}
+ </ResizablePanel>
+ {rightPanel}
</ResizablePanelGroup>
</div>
);
diff --git a/packages/app/src/components/TerminalDock.dom.test.tsx b/packages/app/src/components/TerminalDock.dom.test.tsx
index a858a40d5..2e58b55ed 100644
--- a/packages/app/src/components/TerminalDock.dom.test.tsx
+++ b/packages/app/src/components/TerminalDock.dom.test.tsx
@@ -583,7 +583,7 @@ describe('TerminalDock multi-session', () => {
expect(terminalPanelProps?.collapsible).toBe(true);
expect(terminalPanelProps?.collapsedSize).toBe(0);
expect(terminalPanelProps?.minSize).toBe('120px');
- expect(terminalPanelProps?.maxSize).toBe('50%');
+ expect(terminalPanelProps?.maxSize).toBe('95%');
expect(terminalPanelProps?.defaultSize).toBe(0);
expect(terminalPanelProps?.inert).toBe(true);
});
diff --git a/packages/app/src/components/TerminalDock.tsx b/packages/app/src/components/TerminalDock.tsx
index 1a6940d2b..78b35a5ef 100644
--- a/packages/app/src/components/TerminalDock.tsx
+++ b/packages/app/src/components/TerminalDock.tsx
@@ -205,7 +205,7 @@ export function TerminalDock({
className="min-h-0 flex-1"
data-dragging={isDragging || undefined}
>
- <ResizablePanel minSize="20%" className="flex min-h-0 flex-col">
+ <ResizablePanel minSize="5%" className="flex min-h-0 flex-col">
{/* tabIndex -1 makes this a programmatic focus target for focus-return
on collapse without adding it to the tab order. */}
<div
@@ -237,7 +237,7 @@ export function TerminalDock({
panelRef={panelRef}
defaultSize={visible ? `${initialHeightPx}px` : 0}
minSize="120px"
- maxSize="50%"
+ maxSize="95%"
collapsible
collapsedSize={0}
onResize={(size) => {
diff --git a/packages/app/src/components/TerminalPanel.dom.test.tsx b/packages/app/src/components/TerminalPanel.dom.test.tsx
index f380b06bc..7655b16da 100644
--- a/packages/app/src/components/TerminalPanel.dom.test.tsx
+++ b/packages/app/src/components/TerminalPanel.dom.test.tsx
@@ -187,18 +187,78 @@ describe('TerminalPanel', () => {
expect(terminal.resize).toHaveBeenCalledWith('pty-1', 80, 24);
});
- test('does not intercept keys — Escape and all keystrokes reach the PTY', async () => {
+ test('cancels the browser default for Shift+Tab only; every other key (incl. Escape) reaches the PTY', async () => {
const { bridge, terminal } = makeBridge({ ok: true, ptyId: 'pty-1' });
render(<TerminalPanel bridge={bridge} />);
await waitFor(() => expect(lastTerm?.onDataCb).toBeTruthy());
- expect(lastTerm?.attachCustomKeyEventHandler).not.toHaveBeenCalled();
- expect(lastTerm?.keyHandler).toBeNull();
+ expect(lastTerm?.attachCustomKeyEventHandler).toHaveBeenCalledTimes(1);
+ const handler = lastTerm?.keyHandler;
+ expect(handler).toBeTruthy();
+
+ const shiftTabPreventDefault = mock(() => {});
+ const shiftTab = {
+ type: 'keydown',
+ key: 'Tab',
+ shiftKey: true,
+ preventDefault: shiftTabPreventDefault,
+ } as unknown as KeyboardEvent;
+ expect(handler?.(shiftTab)).toBe(true);
+ expect(shiftTabPreventDefault).toHaveBeenCalledTimes(1);
+
+ const plainTabPreventDefault = mock(() => {});
+ const plainTab = {
+ type: 'keydown',
+ key: 'Tab',
+ shiftKey: false,
+ preventDefault: plainTabPreventDefault,
+ } as unknown as KeyboardEvent;
+ expect(handler?.(plainTab)).toBe(true);
+ expect(plainTabPreventDefault).not.toHaveBeenCalled();
+
+ const escapePreventDefault = mock(() => {});
+ const escapeKey = {
+ type: 'keydown',
+ key: 'Escape',
+ shiftKey: false,
+ preventDefault: escapePreventDefault,
+ } as unknown as KeyboardEvent;
+ expect(handler?.(escapeKey)).toBe(true);
+ expect(escapePreventDefault).not.toHaveBeenCalled();
act(() => lastTerm?.onDataCb?.('\x1b'));
expect(terminal.input).toHaveBeenCalledWith('pty-1', '\x1b');
});
+ test('Shift+Enter sends a newline (LF) to the PTY instead of submitting (CR)', async () => {
+ const { bridge, terminal } = makeBridge({ ok: true, ptyId: 'pty-1' });
+ render(<TerminalPanel bridge={bridge} />);
+ await waitFor(() => expect(lastTerm?.onDataCb).toBeTruthy());
+ const handler = lastTerm?.keyHandler;
+ expect(handler).toBeTruthy();
+
+ const shiftEnterPreventDefault = mock(() => {});
+ const shiftEnter = {
+ type: 'keydown',
+ key: 'Enter',
+ shiftKey: true,
+ preventDefault: shiftEnterPreventDefault,
+ } as unknown as KeyboardEvent;
+ expect(handler?.(shiftEnter)).toBe(false);
+ expect(shiftEnterPreventDefault).toHaveBeenCalledTimes(1);
+ expect(terminal.input).toHaveBeenCalledWith('pty-1', '\n');
+
+ const plainEnterPreventDefault = mock(() => {});
+ const plainEnter = {
+ type: 'keydown',
+ key: 'Enter',
+ shiftKey: false,
+ preventDefault: plainEnterPreventDefault,
+ } as unknown as KeyboardEvent;
+ expect(handler?.(plainEnter)).toBe(true);
+ expect(plainEnterPreventDefault).not.toHaveBeenCalled();
+ });
+
test('disposes the terminal, kills the PTY, and unsubscribes on unmount', async () => {
const { bridge, terminal, unsubData, unsubExit } = makeBridge({ ok: true, ptyId: 'pty-1' });
const { unmount } = render(<TerminalPanel bridge={bridge} />);
diff --git a/packages/app/src/components/TerminalPanel.tsx b/packages/app/src/components/TerminalPanel.tsx
index 603a76e9c..a21202fd7 100644
--- a/packages/app/src/components/TerminalPanel.tsx
+++ b/packages/app/src/components/TerminalPanel.tsx
@@ -137,6 +137,22 @@ function TerminalSession({
fit.fit();
+ term.attachCustomKeyEventHandler((event) => {
+ if (event.type !== 'keydown' || !event.shiftKey) return true;
+ if (event.key === 'Tab') {
+ event.preventDefault();
+ return true;
+ }
+ if (event.key === 'Enter') {
+ const ptyId = ptyIdRef.current;
+ if (ptyId === null) return true;
+ event.preventDefault();
+ bridge.terminal.input(ptyId, '\n');
+ return false;
+ }
+ return true;
+ });
+
void (async () => {
let result: Awaited<ReturnType<typeof bridge.terminal.create>>;
try {