Skip to content

Preserve newlines in notification messages#313709

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-178796-notification-newlines
Open

Preserve newlines in notification messages#313709
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-178796-notification-newlines

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Summary

NotificationViewItem.parseMessage previously flattened all line breaks to spaces:

// Before
message = message.replace(/(\r\n|\n|\r)/gm, ' ').trim();

This PR keeps \n intact and normalizes \r\n / \r to \n. The renderer (NotificationMessageRenderer.render) splits plain string nodes on \n and 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 in parseLinkedText does not span lines, so any \n always ends up in a plain string node before/after a parsed link.
  • src/vs/workbench/browser/parts/notifications/notificationsViewer.ts — when iterating message.linkedText.nodes, split each plain string on \n and 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

  • Expanded notification messages already declare white-space: normal; word-wrap: break-word; and the offset helper used for auto-expansion height calculation already wraps.
  • Collapsed rows have a fixed LINE_HEIGHT (22) with overflow: 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.ts reads notification.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.raw is 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.ts parse path and the notificationsViewer.ts rendering. The conflict is mechanical — one introduces a nodes: NotificationMessageNode[] shape; this one preserves \n in plain text nodes. Whichever lands first, I'm happy to rebase the other.

Test plan

  • New regression test in notifications.test.ts covering: a plain \n is preserved through parsing; \r\n and \r are normalized to \n; leading/trailing newlines are trimmed; newlines coexist with markdown links.
  • Manual: post a notification with \n in the message via vscode.window.showInformationMessage("Line one\nLine two") from an extension or notification.show({ severity: Severity.Info, message: "Line one\nLine two" }) — verify both lines render.
  • Manual: ensure existing single-line notifications render identically (no extra <br>).
  • Manual: a multi-line message with a link mid-message keeps both the line breaks and the parsed link.

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
Copilot AI review requested due to automatic review settings May 1, 2026 11:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support backticks (markdown) in window notifications Notifications should allow new-lines

3 participants