Skip to content

fix(ui): preserve single line breaks in submitted user messages - #3505

Open
joestump wants to merge 1 commit into
charmbracelet:mainfrom
joestump:fix/3502-preserve-user-linebreaks
Open

fix(ui): preserve single line breaks in submitted user messages#3505
joestump wants to merge 1 commit into
charmbracelet:mainfrom
joestump:fix/3502-preserve-user-linebreaks

Conversation

@joestump

@joestump joestump commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

A user message typed as

a
b

c

rendered in the chat as "a b" on one line. Only the display was affected — the content persisted to history and sent to the model was always correct.

User input is rendered through the shared Markdown renderer, where a lone newline is a soft break and adjacent lines are joined into one paragraph. That is correct for Markdown source, but user input is authored in a plain textarea: a newline there is a line the user deliberately typed, not soft wrapping.

Add UserMarkdownRenderer — same styles, width, and Chroma formatter as MarkdownRenderer, plus glamour's WithPreservedNewLines — and use it for user messages only. Assistant output and dialog copy keep the standard renderer, since those really are Markdown and collapsing soft-wrapped paragraphs is the correct rendering there.

The new renderer is memoized per width like its siblings and is cleared by InvalidateMarkdownRendererCache, so a style/palette change does not leave stale user renderers behind.

WithPreservedNewLines only affects soft breaks inside paragraphs and blockquotes: bullet lists, ordered lists, fenced code blocks, tables, and long-line soft wrapping all render byte-identically before and after. Tests cover the reported case, that long lines still wrap, and that those block constructs are unaffected.

Fixes #3502

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

A user message typed as

    a
    b

    c

rendered in the chat as "a b" on one line. Only the display was
affected — the content persisted to history and sent to the model was
always correct.

User input is rendered through the shared Markdown renderer, where a
lone newline is a soft break and adjacent lines are joined into one
paragraph. That is correct for Markdown *source*, but user input is
authored in a plain textarea: a newline there is a line the user
deliberately typed, not soft wrapping.

Add UserMarkdownRenderer — same styles, width, and Chroma formatter as
MarkdownRenderer, plus glamour's WithPreservedNewLines — and use it for
user messages only. Assistant output and dialog copy keep the standard
renderer, since those really are Markdown and collapsing soft-wrapped
paragraphs is the correct rendering there.

The new renderer is memoized per width like its siblings and is cleared
by InvalidateMarkdownRendererCache, so a style/palette change does not
leave stale user renderers behind.

WithPreservedNewLines only affects soft breaks inside paragraphs and
blockquotes: bullet lists, ordered lists, fenced code blocks, tables,
and long-line soft wrapping all render byte-identically before and
after. Tests cover the reported case, that long lines still wrap, and
that those block constructs are unaffected.

Fixes charmbracelet#3502
@charmcli

charmcli commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thank you for your submission. We really appreciate it! Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request comment same as the below format.


I have read the Contributor License Agreement (CLA) and hereby sign the CLA.


Joe Stump seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

single line breaks are not preserved in the input display after submitting

2 participants