From 6c22b883ca7d7dd486eff4a1307d228e8d140c83 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Mon, 23 Nov 2026 19:17:29 +0100 Subject: [PATCH] fix(app): keep focus on the field when the terminal profile takes no prompt A terminal profile without a prompt shows a read-only command preview, so there is nothing to type into. Its pickers now fall back to returning focus to the field that opened them instead of losing focus to the preview. --- .../new-workspace-launch-terminal.spec.ts | 22 +++++++++++++++++++ .../app/src/screens/new-workspace-screen.tsx | 5 +++-- .../src/screens/new-workspace/form/index.tsx | 7 ++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/app/e2e/browser/new-workspace-launch-terminal.spec.ts b/packages/app/e2e/browser/new-workspace-launch-terminal.spec.ts index 7268f7146b..e2ce2f942b 100644 --- a/packages/app/e2e/browser/new-workspace-launch-terminal.spec.ts +++ b/packages/app/e2e/browser/new-workspace-launch-terminal.spec.ts @@ -2,6 +2,7 @@ import { expect, test, type Page } from "../support/fixtures"; import { gotoAppShell } from "../support/helpers/app"; import { waitForSidebarHydration } from "../support/helpers/workspace-ui"; import { + chooseProjectWithKeyboard, expectNewWorkspaceDraft, fillNewWorkspaceDraft, openNewWorkspaceComposer, @@ -109,6 +110,27 @@ test.describe("New workspace: launching a terminal", () => { }); }); + test("with a profile that takes no prompt, choosing a project keeps focus on the Project field", async ({ + page, + }) => { + await gotoAppShell(page); + await waitForSidebarHydration(page); + await openNewWorkspaceComposer(page, { + projectKey: workspace.projectKey, + projectDisplayName: workspace.projectDisplayName, + }); + await selectLaunchOption(page, BARE_PROFILE.id); + await expect(terminalPromptInput(page)).toHaveCount(0); + + // The read-only command preview has nothing to type into, so the picker + // hands focus back to the field that opened it. + const projectTrigger = page.getByTestId("new-workspace-project-picker-trigger"); + await projectTrigger.focus(); + await page.keyboard.press("Enter"); + await chooseProjectWithKeyboard(page, workspace.projectDisplayName); + await expect(projectTrigger).toBeFocused(); + }); + test("switching terminal profiles restores the prompt and its fullscreen affordance", async ({ page, }) => { diff --git a/packages/app/src/screens/new-workspace-screen.tsx b/packages/app/src/screens/new-workspace-screen.tsx index a72c9ee1aa..3db430d57a 100644 --- a/packages/app/src/screens/new-workspace-screen.tsx +++ b/packages/app/src/screens/new-workspace-screen.tsx @@ -1579,7 +1579,8 @@ export function NewWorkspaceScreen({ : t("newWorkspace.refPicker.noMatchingRefs"); // The prompt is where the user types; when a field's picker closes, focus returns there rather - // than to whatever had focus when the picker opened. + // than to whatever had focus when the picker opened. A terminal profile that takes no prompt + // shows a read-only command preview, so its pickers keep returning focus to their field. const composerFocusRef = useRef<{ focus: () => void } | null>(null); const handleComposerFocusInput = useCallback((focus: () => void) => { composerFocusRef.current = { focus }; @@ -1588,7 +1589,7 @@ export function NewWorkspaceScreen({ const formStack = useNewWorkspaceForm({ isCompact, isPending, - restoreFocusRef: composerFocusRef, + restoreFocusRef: terminalTakesPrompt ? composerFocusRef : undefined, pluginItems: ( ), diff --git a/packages/app/src/screens/new-workspace/form/index.tsx b/packages/app/src/screens/new-workspace/form/index.tsx index 014f51ad7e..8fa6225820 100644 --- a/packages/app/src/screens/new-workspace/form/index.tsx +++ b/packages/app/src/screens/new-workspace/form/index.tsx @@ -67,8 +67,11 @@ export interface NewWorkspaceFormProps { isPending: boolean; /** Plugin fields, drawn after the base ref. */ pluginItems: ReactNode; - /** Where focus goes when a field's picker closes, so the user keeps typing the prompt. */ - restoreFocusRef: RefObject; + /** + * Where focus goes when a field's picker closes, so the user keeps typing the prompt. Without + * one, focus returns to the field that opened the picker. + */ + restoreFocusRef?: RefObject; project: PickerControl & { options: ComboboxOption[]; projectByOptionId: Map;