Preserve newlines in notification messages#313709
Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Open
Preserve newlines in notification messages#313709maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The notifications view item parse path previously flattened all line breaks to spaces. This change normalizes carriage returns to '\n' but keeps '\n' intact, and the renderer splits plain string nodes on '\n' to emit line breaks. Link parsing is unaffected because newlines never appear inside the bracketed/parenthesized link span. Fixes microsoft#178796
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.
Summary
NotificationViewItem.parseMessagepreviously flattened all line breaks to spaces:This PR keeps
\nintact and normalizes\r\n/\rto\n. The renderer (NotificationMessageRenderer.render) splits plain string nodes on\nand emits a<br>between segments, so multi-line notification messages render with the line breaks the producer intended.Fixes #178796
Implementation
src/vs/workbench/common/notifications.ts— change the parse-time strip to a normalize-to-\n. Link parsing still works because the link pattern inparseLinkedTextdoes not span lines, so any\nalways ends up in a plain string node before/after a parsed link.src/vs/workbench/browser/parts/notifications/notificationsViewer.ts— when iteratingmessage.linkedText.nodes, split each plain string on\nand emit a<br>element between segments. Empty segments are skipped so a trimmed-trailing-newline message doesn't append a stray<br>.No CSS changes needed
white-space: normal; word-wrap: break-word;and the offset helper used for auto-expansion height calculation already wraps.LINE_HEIGHT (22)withoverflow: hidden, so the single-line preview look is preserved while the offset helper correctly computes a taller preferred height — driving auto-expansion already works.Accessibility
notificationsAlerts.tsreadsnotification.message.linkedText.toString()for ARIA alerts. Screen readers naturally pause at\n, so multi-line announcements read more naturally than today's space-flattened output.message.rawis unchanged — it's set before the parse-time normalization, so existing aria-label/clipboard-copy callers (notificationsToasts.ts,notificationsList.ts,notificationsActions.ts) see no behavior difference.Conflict note for reviewers
This PR conflicts with my open PR #313707 (Render inline code spans in notification messages, fixes #191713) on the same two files. Both touch the
notifications.tsparse path and thenotificationsViewer.tsrendering. The conflict is mechanical — one introduces anodes: NotificationMessageNode[]shape; this one preserves\nin plain text nodes. Whichever lands first, I'm happy to rebase the other.Test plan
notifications.test.tscovering: a plain\nis preserved through parsing;\r\nand\rare normalized to\n; leading/trailing newlines are trimmed; newlines coexist with markdown links.\nin the message viavscode.window.showInformationMessage("Line one\nLine two")from an extension ornotification.show({ severity: Severity.Info, message: "Line one\nLine two" })— verify both lines render.<br>).