Skip to content

fix(chat): Keep the newlines in a paste to the composer - #708

Merged
omesser merged 2 commits into
mainfrom
fix/686-composer-newlines
Sep 15, 2026
Merged

omesser merged 2 commits into
mainfrom
fix/686-composer-newlines

Conversation

@omesser

@omesser omesser commented Sep 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #686

What was wrong

<input type="text"> runs HTML's value sanitization, which deletes every LF and CR rather than folding them to spaces. A pasted function did not arrive flattened — it arrived glued: }function next(. The log renders with white-space: pre-wrap, so it faithfully showed a value that never had newlines in it, and nothing said so.

The change

src/chat.html:216 — the composer is a <textarea rows="1">. The sanitization does not apply, so the newlines survive into line.value and into chat_send.

Three decisions follow, each named in the code:

Send. src/chat.js:453 — an <input> in a form submits on Enter for free, which is why this window shipped with no keydown listener at all. A textarea does not, so Enter is wired by hand: Enter sends, Shift+Enter types the newline, and event.isComposing is left alone so an IME's Enter accepts its candidate instead of cutting the word in half. It calls composer.requestSubmit() rather than sending itself, so the empty-line and attach guards in the existing submit listener still run — there is still exactly one invoke("chat_send") in the file, and a test pins that.

Height. src/chat-ui.css:678 — the Chat surface is 420 by 560 points (src-tauri/src/main.rs:836) and the composer sits under the log, so height the field takes is height the conversation loses. rows="1" at rest, max-height: calc(1.5em * 5 + 22px), overflow-y: auto, resize: none. field-sizing: content lets the field follow its content up to that clamp; where an engine has not got it the field stays at its one row, which is exactly the shape shipped today, so the fallback is not a regression.

One line outside the composer. The issue attributes that geometry to ADR-0012, and so did showTab's comment at src/chat.js:357. ADR-0012 is the Instance Prompt's own decision and says nothing about window size — main.rs is where the 420×560 actually lives, which is how src/chat-ask.js:18 already cites it. The mistake started in showTab and was copied from there into the issue, so the citation is corrected where it started rather than propagated one file further.

#641's layout trap. The composer's form is flex, not grid, so no .prompt-field-style wrapper was needed — but the field carries min-width: 0 and box-sizing: border-box for the same reason that wrapper exists.

Verification

cargo test --workspace: 959 passed, 0 failed, 4 ignored. node --test tests/: 132 tests, 132 pass, 0 fail. pre-commit run --all-files: all pass.

WebView2 could not be run — this is a Mac, and I am not claiming otherwise. What I did instead was render the composer's real CSS in headless Chromium, the same engine family, and measure it rather than eyeball it:

case field right edge vs track scrollHeight
empty 313 × 42 339 vs 430 40
3 lines pasted 313 × 81 339 vs 430 79
30 lines pasted 313 × 120 339 vs 430 605
one 400-char token 313 × 120 339 vs 430 215

At rest it is the single row it has always been; it clamps at 120px (calc(1.5em * 5 + 22px)) and scrolls inside itself; its right edge stays well inside the track in both the many-lines and the one-long-token case, so the #641 class of overflow does not appear. value.includes("\n") is true on the pasted cases — the bug in one assertion. A WebView2 look is still worth someone's minute on Windows.

Tests

tests/chat-composer.test.js is new, in the style of tests/chat-prompt.test.js: the field is a textarea and the sanitizing input is gone; Enter is the send key and Shift+Enter is not; the send key goes through requestSubmit rather than opening a second send path; the field rests at one row and clamps; no rule is left addressed to .composer input. Each of them fails on origin/main.

tests/chat-prompt.test.js had a blanket ban on typing listeners, because a keystroke that saves an Instance Prompt throws the session away. The ban now names the one exemption — line.keydown — and adds the sharper assertion the ban was always about: that handler cannot reach invoke(.

Sequencing

Review

/code-review ran both axes against origin/main. Both independently flagged the ADR-0012 miscitation described above; it is fixed, in all three places the change introduced it and in the showTab line it came from. Two further findings I did not act on, with reasons:

  • Duplicated Code (judgement call): the four-line indexOf locator for the keydown handler appears in both test files. A shared test-helper module for two callers is more machinery than it saves; worth extracting at a third.
  • Scope creep: event.isComposing. The spec asks for "Enter sends, Shift+Enter inserts a newline". isComposing is what makes that handler correct rather than what extends it — without it an IME's Enter, which confirms a candidate, would send a half-typed word. One condition, no new behaviour surface.

Out of scope, as the issue says

CHAT_LIMIT and its silent cut (#685), file attachment, Markdown rendering of replies (#677). The reply-row and ask-row paths in src/chat.js are untouched.

🤖 Generated with Claude Code

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Architect gate: CHANGES_REQUESTED @ 38d1fa7 (rebase / MERGEABLE)

Spec (#686) — looks good once conflict cleared

  • Composer input type=text → textarea rows="1" so LF/CR survive paste (root cause).
  • Enter → composer.requestSubmit() (one chat_send path); Shift+Enter / isComposing fall through.
  • Height clamp + overflow-y: auto + min-width: 0 / box-sizing (#641 class).
  • ADR-0012 mis-cite on showTab corrected to main.rs.
  • Tests pin textarea, Enter/Shift+Enter, single send path, CSS clamp, no leftover .composer input rules; chat-prompt typing-ban exempts line.keydown without invoke(.

Hard blocker

CONFLICTING with main. #707 (maxlength="16000" / #685) already merged; this tip still replaces the pre-#707 <input> hunk. Resolution (as PR body already says): keep <textarea> and keep maxlength="16000" (plus the #685 comment on the field). Prefer rebase onto current main, not a blind recreate.

Until MERGEABLE + CI green on the rebased tip: not CLEARED.

Soft

  • WebView2 live look still unpaid (PR Notes); Chromium headless evidence is fine for this gate if Windows smoke is a follow-up.
  • session/prompt-style ACP strings N/A here.

CI on the pre-rebase tip was green; re-check after rebase.

— Cursor agent (Architect), on @omesser's behalf.

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Standards addendum @ 38d1fa7 (still CHANGES_REQUESTED)

With the rebase, also:

comments.md: Drop history narrative in src/chat.js:

  • showTab: keep “420 points (main.rs); ADR-0012 is the Instance Prompt decision” — remove “used to cite it / copied into #686.”
  • keydown opener: keep why Enter needs a listener (textarea, #686, IME) — drop “became / input it replaced” before/after.

Conflict resolution unchanged: textarea + maxlength="16000".

— Cursor agent (Architect), on @omesser's behalf.

omesser and others added 2 commits September 15, 2026 00:25
`type=text` value sanitization deletes every LF and CR, so a pasted
function reached the Harness with each line glued to the next. The
composer is a textarea now, which keeps them.

A textarea does not submit its form on Enter, so Enter is wired by hand:
it sends, Shift+Enter types the newline. The field rests at one row and
clamps at five, because the Chat surface is 420 by 560 points
(`main.rs`) and the log above it has no height to give.

`showTab` attributed that geometry to ADR-0012, which is the Instance
Prompt's own decision and says nothing about it. #686 copied the
mistake, so the citation is corrected where it started.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Oded Messer <odedmesser@gmail.com>
@cursor
cursor Bot force-pushed the fix/686-composer-newlines branch from 38d1fa7 to ad33447 Compare September 15, 2026 00:26
@omesser

omesser commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto latest main (post-#707).

New tip: ad33447

Conflict resolution: Preserved both the <textarea> element (for newline handling) and maxlength=16000 (from #707), plus the #685 field comment. Applied comment trims per comments.md (showTab and keydown).

Status: MERGEABLE. Conflicts resolved, tests pass (134 JS tests green).

— Cursor agent (Coder), on @omesser's behalf.

@omesser

omesser commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

Architect gate: CLEARED @ ad334475 (CI pending)

Spec (#686)

Standards

History narrative trimmed from showTab and keydown opener comments — matches prior addendum.

Mergeability

MERGEABLE onto main (conflict with #707 resolved correctly: textarea + maxlength).

Soft (non-blocking)

WebView2 live look still unpaid; Chromium headless evidence in PR body is enough for this gate.

CI still running on this tip — merge-ready only when PR Tests are green. Architect does not merge.

— Cursor agent (Architect), on @omesser's behalf.

@omesser

omesser commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

Architect gate: merge-ready @ ad334475

CI green on this tip (ubuntu / macos / windows + Pages build). Spec/Standards CLEARED earlier; MERGEABLE/CLEAN.

Architect does not merge — yours when you want it.

#708

— Cursor agent (Architect), on @omesser's behalf.

@omesser
omesser merged commit c191661 into main Sep 15, 2026
5 checks passed

@omesser omesser left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Architect gate: CLEARED @ ad33447

Rebase onto main after #707 looks right:

  • <textarea id="line" rows="1" maxlength="16000" …> — newlines kept and #685 field bound.
  • #685 maxlength comment retained above the form.
  • showTab cites main.rs only (no history).
  • keydown comment is constraint-only (textarea / Enter / Shift+Enter / IME).

Spec (#686) unchanged and still met. CI green; MERGEABLE. Soft: WebView2 live look still optional follow-up.

Ready for Oded to merge — Architect does not merge.

— Cursor agent (Architect), on @omesser's behalf.

@omesser

omesser commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

Hard blocker cleared. Rebased onto current main (which now carries #707 as e3d14b68); tip is ad33447.

The src/chat.html hunk resolved as directed: the element stays a <textarea> and keeps maxlength="16000", with #685's comment above the field left as #707 wrote it. That comment still reads true against a textarea — it speaks of "the field" throughout, so no word needed changing. maxlength is a textarea content attribute, and the spec applies it to the API value, whose line breaks are normalized to LF, so the bound counts the newlines this PR preserves rather than ignoring them.

The bound still binds: no programmatic write to line.value was added. Enter goes through composer.requestSubmit() and Shift+Enter falls through to the native insert, so the only writes are the one read in submit and the clear to "" — the field cannot outrun chat_send's .take().

Both composer suites pass together on the rebased tip, neither needing a touch-up: #707's chat-composer-limit and this PR's chat-composer.

mergeable: MERGEABLE, mergeStateStatus: CLEAN. CI green at the tip — checks (ubuntu-latest), checks (macos-latest), windows and build all SUCCESS, deploy skipped. Locally cargo test --workspace is 962 passed / 0 failed and node --test tests/ is 134 pass / 0 fail.

The Standards addendum's comment trim landed in the same tip.

— Claude Code agent, on @omesser's behalf.

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.

fix(chat): The composer drops the newlines out of a pasted file

2 participants