Skip to content

fix(app): insert a line break on Enter in touch composers - #56664

Open
kanswer wants to merge 1 commit into
anomalyco:devfrom
kanswer:composer-touch-newline
Open

kanswer wants to merge 1 commit into
anomalyco:devfrom
kanswer:composer-touch-newline

Conversation

@kanswer

@kanswer kanswer commented Oct 18, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #55549

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On touch devices, the composer submits the prompt on every plain Enter press. Mobile soft keyboards have no Shift key, so there is no way to compose a multi-line prompt at all.

This adds a touch branch to onKeyDown in packages/app/src/composer/editor/editor.tsx: when the device has no hover pointer (@media (hover: none)), plain Enter inserts a line break instead of submitting, and the send button remains the way to submit. Mod+Enter still submits for external keyboards, and desktop behavior (Enter submits, Shift+Enter inserts a newline) is unchanged.

The break is inserted with document.execCommand("insertLineBreak"), which produces the same DOM as desktop Shift+Enter — the path the composer's parser already handles — so the newline survives submission as a single \n. preventDefault() is only called when the insertion succeeds; if the command returns false, the browser's default insertion still runs, so Enter never submits either way. I used a (hover: none) media query rather than a viewport width check because landscape phones (e.g. 844px) and tablets would be missed by a < 768px rule.

How did you verify your code works?

  • Added a case to the existing composer e2e keeper, e2e/regression/mobile-composer-submit-focus.spec.ts (touch context, 390px): type "first line", press Enter, type "second line", tap Send, then assert the POSTed prompt text is exactly "first line\nsecond line" and the composer is emptied. The case fails on dev (Enter submits immediately) and passes with the change.
  • --repeat-each=10 --workers=4 --retries=0 for the new case: 10/10 passed. The full spec file: 5/5 passed.
  • bun run typecheck (packages/app) and bun run typecheck:e2e are clean for the changed files.

Screenshots / recordings

Before — Enter submits immediately and the composer is emptied:

before

After — Enter keeps both lines in the composer, and the send button submits them as one prompt:

after

sent

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #43088, #55341

Touch keyboards have no Shift key, so plain Enter now inserts the same line
break as Shift+Enter on desktop, and the send button submits the prompt.
Mod+Enter still submits for external keyboards, and desktop behavior is
unchanged.

Fixes anomalyco#55549
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I reproduced the bug in Playwright on an emulated touch phone (390px, hasTouch/isMobile). On the base, Enter sent "first line" and left only "second line" in the composer. With this change no prompt is sent, the composer holds first line\nsecond line, and Send submits it. Your new e2e case fails on the base and passes here. The rest of the spec (desktop and non-touch 390px, where Enter still sends) passes on both. Enter in the suggestion popover behaves the same as on the base, because controller.onKeyDown runs before the new branch. bun run typecheck is clean.

The public API is unchanged.

One small point: on a touch device with a hardware keyboard (for example an iPad keyboard without a trackpad, which still matches (hover: none)), the only way to send from the keyboard is now Mod+Enter. That key is the alternate delivery (it switches queue/steer while a turn is running), not a plain submit. It's probably fine for this fix, but it's worth knowing that it isn't quite "Mod+Enter still submits".

Related: #43088, #55341

Before

After

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web: on mobile, Enter submits the prompt and no newline can be inserted

1 participant