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
28 changes: 28 additions & 0 deletions apps/app/src/components/promptbox/PromptBoxInternal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,34 @@ describe("PromptBoxInternal compact layout", () => {
).toBe(true);
});

it("keeps the editor focused through a pointer submit", async () => {
const onSubmit = vi.fn();
render(
<PromptBoxInternal
{...createPromptBoxProps({
value: "Send this follow-up",
onSubmit,
compact: {
isCompact: true,
placeholder: "Ask a follow-up",
},
})}
/>,
);

await waitForPromptFocus();
const editor = getPromptEditorElement();
const submit = screen.getByRole("button", { name: "Submit (Enter)" });

expect(
fireEvent.pointerDown(submit, { button: 0, pointerType: "touch" }),
).toBe(false);
expect(document.activeElement).toBe(editor);

fireEvent.click(submit);
expect(onSubmit).toHaveBeenCalledOnce();
});

it("keeps all Markdown and mention text in the navigable preview", async () => {
const mentionToken =
"@apps/app/src/components/promptbox/PromptBoxInternal.tsx";
Expand Down
23 changes: 23 additions & 0 deletions apps/app/src/components/promptbox/PromptBoxInternal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
type ChangeEvent,
type FormEvent,
type MouseEvent as ReactMouseEvent,
type PointerEvent as ReactPointerEvent,
type ReactNode,
type Ref,
} from "react";
Expand Down Expand Up @@ -2319,6 +2320,27 @@ export function PromptBoxInternal({
resetZenModeAfterSubmit();
}, [canSubmit, onSubmit, resetZenModeAfterSubmit]);

const handleSubmitPointerDown = useCallback(
(event: ReactPointerEvent<HTMLButtonElement>) => {
if (event.button !== 0) return;
const currentEditor = editorRef.current;
if (
!currentEditor ||
currentEditor.isDestroyed ||
!currentEditor.isFocused
) {
return;
}

// Focus transfer happens before click. On iOS, moving focus from the
// editor to this button begins keyboard dismissal and resizes the app
// shell before the form can submit. Keep the editor focused; the click
// still owns the commit, while genuine outside focus dismisses normally.
event.preventDefault();
},
[],
);

// A no-argument built-in command (currently only `/compact`) is a complete
// action the moment it is selected, so applying it with Enter should also
// submit instead of leaving the pill parked for a second Enter. The submit is
Expand Down Expand Up @@ -3028,6 +3050,7 @@ export function PromptBoxInternal({
variant="default"
aria-label={effectiveSubmitTitle}
disabled={!canSubmit}
onPointerDown={handleSubmitPointerDown}
className={cn(
showCompactLayout
? COMPACT_PROMPT_ACTION_BUTTON_CLASS
Expand Down
Loading