Repository navigation
fix(editor): preserve CRLF across large paste chunks - #34976
Conversation
a7c8d63 to
e483e11
Compare
[Medium impact] The PR appears safe to merge. SummaryKeeps CRLF pairs together when large pastes are split into chunks, preventing extra blank lines.
No actionable issues found. Tests were not run. Reviews (2) · Last reviewed commit: "fix(editor): keep CRLF pairs in one chun..." · Reviewed by Greptile |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Walkthrough
Priority: Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
b9e1ee3a-71c1-42bb-93e2-59c906160709
Files selected for processing: 2-
src/renderer/src/components/editor/monaco-large-text-paste.crlf.test.tssrc/renderer/src/components/editor/monaco-large-text-paste.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
-
| chunkMaxBytes, | ||
| yieldToEventLoop: async () => {} | ||
| }) | ||
| expect(model.getValue()).toBe('aaa\nb') |
There was a problem hiding this comment.
Make the assertion independent of the platform EOL.
On Windows, the empty model defaults to CRLF, so getValue() returns aaa\r\nb. Both cases fail even when the paste is correct. Set the model EOL explicitly or request LF from getValue(). (raw.githubusercontent.com)
Monaco normalizes line endings per edit, so splitting a CR from its LF across chunked executeEdits calls inserted an extra blank line.
e483e11 to
c0a9be1
Compare
Problem
Pastes over 64 KiB go into Monaco in 16 KiB chunks, and each chunk is a separate
executeEditscall. Monaco normalizes line endings in each edit's text on its own (PieceTreeTextBuffer.applyEdits). If a chunk boundary falls between the\rand\nof a CRLF pair, the trailing\rbecomes one line break and the leading\nof the next chunk becomes a second one, so a blank line is silently added to the file. This affects both Ctrl/Cmd+V and context-menu Paste, and is most likely with CRLF clipboard text, which is the normal case on Windows.Fix
In
insertMonacoTextInChunks, when a chunk would end on a\rthat is followed by\n, the chunk ends one code unit earlier so the pair stays in the next edit. With a 1-byte budget, the chunk grows to include the\ninstead, so a chunk is never empty. Since the moved code unit is always\r, a surrogate pair can't be split.Test
monaco-large-text-paste.crlf.test.tspastesaaa\r\nbthrough a real Monaco text model with 1-byte and 4-byte chunk budgets and asserts the result has a single newline. Both cases fail without the fix.