Repository navigation
fix(chat): Keep the newlines in a paste to the composer - #708
Conversation
omesser
left a comment
There was a problem hiding this comment.
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()(onechat_sendpath); Shift+Enter /isComposingfall through. - Height clamp +
overflow-y: auto+min-width: 0/box-sizing(#641 class). - ADR-0012 mis-cite on
showTabcorrected tomain.rs. - Tests pin textarea, Enter/Shift+Enter, single send path, CSS clamp, no leftover
.composer inputrules;chat-prompttyping-ban exemptsline.keydownwithoutinvoke(.
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
left a comment
There was a problem hiding this comment.
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.
`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>
38d1fa7 to
ad33447
Compare
|
Rebased onto latest main (post-#707). New tip: ad33447 Conflict resolution: Preserved both the Status: MERGEABLE. Conflicts resolved, tests pass (134 JS tests green). — Cursor agent (Coder), on @omesser's behalf. |
Architect gate: CLEARED @
|
omesser
left a comment
There was a problem hiding this comment.
Architect gate: CLEARED @ ad33447
Rebase onto main after #707 looks right:
<textarea id="line" rows="1" maxlength="16000" …>— newlines kept and #685 field bound.#685maxlength comment retained above the form.showTabcitesmain.rsonly (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.
|
Hard blocker cleared. Rebased onto current The The bound still binds: no programmatic write to Both composer suites pass together on the rebased tip, neither needing a touch-up: #707's
The Standards addendum's comment trim landed in the same tip. — Claude Code agent, on @omesser's behalf. |
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 withwhite-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 intoline.valueand intochat_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, andevent.isComposingis left alone so an IME's Enter accepts its candidate instead of cutting the word in half. It callscomposer.requestSubmit()rather than sending itself, so the empty-line and attach guards in the existingsubmitlistener still run — there is still exactly oneinvoke("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: contentlets 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 atsrc/chat.js:357. ADR-0012 is the Instance Prompt's own decision and says nothing about window size —main.rsis where the 420×560 actually lives, which is howsrc/chat-ask.js:18already cites it. The mistake started inshowTaband 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 carriesmin-width: 0andbox-sizing: border-boxfor 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:
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")istrueon the pasted cases — the bug in one assertion. A WebView2 look is still worth someone's minute on Windows.Tests
tests/chat-composer.test.jsis new, in the style oftests/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 throughrequestSubmitrather 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 onorigin/main.tests/chat-prompt.test.jshad 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 reachinvoke(.Sequencing
e3d14b68, puttingmaxlength="16000"on the sameid="line"element this PR replaces, so the rebase conflicted in exactly that hunk. It was resolved the only way that keeps both fixes: the element is a<textarea>and it carriesmaxlength="16000", with fix(chat): The typed-line cap is documented wrong, applied silently, and sized for a pet #685's comment above the field left as fix(chat): Bound a typed line at 16000 in the field, not after Send #707 wrote it.maxlengthis atextareacontent attribute, and the spec applies it to the API value — the one whose line breaks are normalized to LF — so the bound counts the newlines this PR preserves rather than ignoring them. fix(chat): Bound a typed line at 16000 in the field, not after Send #707's own test reads<(?:input|textarea)\b[^>]*\bid="line"[^>]*>and passes against a textarea; both PRs' composer tests pass together on the rebased tip, neither needing a change.src/chat.jsandsrc/chat-ui.css, but at disjoint regions: feat(chat): Draw a reply's Markdown instead of its source #705's JS hunks are at lines 16, 110 and 128 (imports,said,opening_answer), mine is at 453; feat(chat): Draw a reply's Markdown instead of its source #705's CSS insert is at line 404 (the Markdown reply block), mine at 678. No textual conflict either order. feat(chat): Draw a reply's Markdown instead of its source #705 merging first still respects the issue author's preference.Review
/code-reviewran both axes againstorigin/main. Both independently flagged the ADR-0012 miscitation described above; it is fixed, in all three places the change introduced it and in theshowTabline it came from. Two further findings I did not act on, with reasons:indexOflocator 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.event.isComposing. The spec asks for "Enter sends, Shift+Enter inserts a newline".isComposingis 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_LIMITand its silent cut (#685), file attachment, Markdown rendering of replies (#677). The reply-row and ask-row paths insrc/chat.jsare untouched.🤖 Generated with Claude Code