Skip to content

Handle trailing line breaks when pasting text - #6069

Open
volksec wants to merge 3 commits into
secondlife:developfrom
volksec:agent/fix-trailing-newline-paste
Open

Handle trailing line breaks when pasting text#6069
volksec wants to merge 3 commits into
secondlife:developfrom
volksec:agent/fix-trailing-newline-paste

Conversation

@volksec

@volksec volksec commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Handle a trailing newline as a line break when pasting into LLTextEditor, instead of inserting it as a regular character.

Fixes #5871.

Root cause

LLTextEditor::pasteTextWithLinebreaks() excluded a newline at the final position from its line-break loop. The remaining substring, including the trailing newline, was then passed to the regular text insertion path. On Windows this could render as an unexpected special character; on macOS it could appear as a space.

Changes

  • Process every newline through addLineBreakChar(), including a trailing newline.
  • Keep internal line breaks grouped with the following text for undo.
  • End the undo group when the pasted text ends with a line break.

Validation

  • pre-commit run --files indra/llui/lltexteditor.cpp
  • git diff --check
  • cmake --build build-vc170-64 --config Release --target llui -- /m
  • cmake --build build-vc170-64 --config Release --target secondlife-bin -- /m

Both llui.lib and secondlife-bin.exe were built successfully with Visual Studio 2022. Manual runtime reproduction is still pending.

Signed-off-by: Luan Nutels - VolkSec <luan.nutels@owasp.org>
@volksec
volksec marked this pull request as ready for review July 29, 2026 22:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes newline handling in LLTextEditor::pasteTextWithLinebreaks() so a trailing \n in pasted text is processed as an actual line break (via addLineBreakChar()), instead of being inserted through the normal text path where it can render as an unexpected glyph/space on Windows/macOS.

Changes:

  • Iterate through all newline occurrences (including a final trailing newline) and route each through addLineBreakChar().
  • Stop “group with next” undo-grouping when the pasted content ends with a line break.
  • Avoid attempting an empty trailing substring insertion after processing the last newline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Pasting copied text with a trailing newline inserts an unexpected special character at the end

2 participants