Skip to content

fix(editor): preserve CRLF across large paste chunks - #34976

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/editor-paste-crlf
Oct 29, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/editor-paste-crlf

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4

Problem

Pastes over 64 KiB go into Monaco in 16 KiB chunks, and each chunk is a separate executeEdits call. Monaco normalizes line endings in each edit's text on its own (PieceTreeTextBuffer.applyEdits). If a chunk boundary falls between the \r and \n of a CRLF pair, the trailing \r becomes one line break and the leading \n of 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 \r that 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 \n instead, 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.ts pastes aaa\r\nb through 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.

@OrcaWin
OrcaWin force-pushed the OrcaWin/editor-paste-crlf branch 2 times, most recently from a7c8d63 to e483e11 Compare October 28, 2026 23:02
@OrcaWin
OrcaWin marked this pull request as ready for review October 29, 2026 00:08
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Keeps CRLF pairs together when large pastes are split into chunks, preventing extra blank lines.

  • Large Monaco pastes keep each CRLF newline in one edit.

No actionable issues found. Tests were not run.

Reviews (2) · Last reviewed commit: "fix(editor): keep CRLF pairs in one chun..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: cd02726f-40aa-44d3-acdf-0d3fb90590e7
Commits

Reviewing files that changed from the base of the PR and between e483e11 and c0a9be1.

Files selected for processing: 2
  • src/renderer/src/components/editor/monaco-large-text-paste.crlf.test.ts
  • src/renderer/src/components/editor/monaco-large-text-paste.ts
Walkthrough

Chunked Monaco paste now adjusts chunk boundaries to keep CRLF pairs together. The new parameterized test checks the result for chunk budgets of 1 and 4 bytes. Each case pastes aaa\r\nb and expects the model value aaa\nb.

Priority: Normal

Merge Risk: Moderate · previous review e483e

The new paste test can fail on Windows despite correct behavior. Make its EOL comparison platform-independent before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description follows the repository template closely. It explains the problem, the fix mechanism, and the test. The LoC summary block is auto-generated and is left in place. The description does no… Add an ELI5 section in plain language. Add a What Changed section that describes the before and after behavior. Add a Why section that explains why the chosen approach beats alternatives. Add a Linked Issue section with a real issue referen…
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "fix(editor): preserve CRLF across large paste chunks" matches the main change. The diff adds a fix in insertMonacoTextInChunks so a CRLF pair stays in one chunk during large pastes, and add…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(editor): preserve CRLF across large paste chunks" matches the main change. The diff adds a fix in insertMonacoTextInChunks so a CRLF pair stays in one chunk during large pastes, and adds a test for it. The title names the affected area (editor), the behavior kept (CRLF), and the context (large paste chunks). It uses a conventional commit style and is 52 characters long.

Full details: Description check

Explanation

The description follows the repository template closely. It explains the problem, the fix mechanism, and the test. The LoC summary block is auto-generated and is left in place. The description does not include the ELI5, What Changed, Why, or Linked Issue sections as the template requires. It has no Fixes # issue link, no Visual Proof section, no Testing checklist ticks, and no AI Disclosure or Review or Agent skill upstream boundary sections. The Checklist is also absent. The Visual Proof section is likely N/A for a non-UI fix, but the author did not write N/A with a reason. Because the template requires a linked issue for outside contributors and several required sections are missing, the description is incomplete.

Resolution

Add an ELI5 section in plain language. Add a What Changed section that describes the before and after behavior. Add a Why section that explains why the chosen approach beats alternatives. Add a Linked Issue section with a real issue reference (Fixes #NNN). Add a Visual Proof section, or write N/A with the reason that the change has no UI effect. Complete the Testing section: state which platforms were tested, and tick the manual testing and automated test boxes as applicable. Complete the AI Disclosure section or confirm it does not apply. Complete the Agent skill upstream boundary checkbox. Complete the Checklist.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

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
Commits

Reviewing files that changed from the base of the PR and between 9dd4dc5 and e483e11.

Files selected for processing: 2
  • src/renderer/src/components/editor/monaco-large-text-paste.crlf.test.ts
  • src/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')

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.

Major · Functional Correctness · Quick win

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.
@OrcaWin
OrcaWin force-pushed the OrcaWin/editor-paste-crlf branch from e483e11 to c0a9be1 Compare October 29, 2026 00:27
@OrcaWin
OrcaWin merged commit 90da325 into main Oct 29, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant