fix(ui): preserve single line breaks in submitted user messages - #3505
Open
joestump wants to merge 1 commit into
Open
fix(ui): preserve single line breaks in submitted user messages#3505joestump wants to merge 1 commit into
joestump wants to merge 1 commit into
Conversation
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
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user message typed as
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
CONTRIBUTING.md.