Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
📝 WalkthroughWalkthroughModified trailing newline handling in file parsing and markdown reconstruction. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src-tauri/src/commands/files.rs`:
- Around line 406-409: The code that restores the trailing newline currently
only pushes '\n' when original_ends_with_newline && !body_content.is_empty(),
which breaks round-trip for inputs that collapse to empty (e.g. "\n\n" or docs
whose content was removed by extract_imports_from_content()); update the logic
in the code that builds body_content (referencing the variables
original_ends_with_newline and body_content and the function
extract_imports_from_content) to restore the trailing newline whenever
original_ends_with_newline is true (remove the body_content.is_empty() guard or
otherwise ensure a single '\n' is appended even for empty body_content) so
blank-only bodies remain a single newline on round-trip.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: b1f4c812-33c6-46f6-8caf-0298ce244c41
⛔ Files ignored due to path filters (1)
docs/tasks-done/task-2026-03-31-fix-editor-scroll-jump.mdis excluded by!**/*.md
📒 Files selected for processing (1)
src-tauri/src/commands/files.rs
| // Preserve trailing newline that lines() dropped. | ||
| // lines() always drops exactly one trailing \n, so always add one back. | ||
| if original_ends_with_newline && !body_content.is_empty() { | ||
| body_content.push('\n'); |
There was a problem hiding this comment.
Blank-only bodies still round-trip as empty content.
These branches only restore a newline when body_content is non-empty, but extract_imports_from_content() collapses inputs like "\n\n" or ---\ntitle: Test\n---\n\n to "". Those files will still reload as empty content, so the editor can keep seeing a mismatch on otherwise-empty docs.
Also applies to: 453-456
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src-tauri/src/commands/files.rs` around lines 406 - 409, The code that
restores the trailing newline currently only pushes '\n' when
original_ends_with_newline && !body_content.is_empty(), which breaks round-trip
for inputs that collapse to empty (e.g. "\n\n" or docs whose content was removed
by extract_imports_from_content()); update the logic in the code that builds
body_content (referencing the variables original_ends_with_newline and
body_content and the function extract_imports_from_content) to restore the
trailing newline whenever original_ends_with_newline is true (remove the
body_content.is_empty() guard or otherwise ensure a single '\n' is appended even
for empty body_content) so blank-only bodies remain a single newline on
round-trip.
Summary by CodeRabbit