Skip to content

Fix editor Scroll Jump#174

Merged
dannysmith merged 4 commits intomainfrom
fix/editor-scroll-jump
Mar 31, 2026
Merged

Fix editor Scroll Jump#174
dannysmith merged 4 commits intomainfrom
fix/editor-scroll-jump

Conversation

@dannysmith
Copy link
Copy Markdown
Owner

@dannysmith dannysmith commented Mar 31, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Corrected trailing newline handling in file save and reload operations to properly preserve intended line endings in markdown content, including files with frontmatter and imports.
    • Enhanced consistency in newline behavior across different file reconstruction scenarios.
    • Added comprehensive test coverage for trailing newline preservation during save-reload cycles.

dannysmith and others added 4 commits March 31, 2026 04:39
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

Modified trailing newline handling in file parsing and markdown reconstruction. The parse_frontmatter function now unconditionally restores newlines when the original input ends with one, and three markdown rebuild helpers no longer forcibly append newlines to reconstructed outputs. Added comprehensive unit tests for trailing-newline round-trip scenarios.

Changes

Cohort / File(s) Summary
Newline Handling Logic
src-tauri/src/commands/files.rs
Updated parse_frontmatter to unconditionally restore newlines matching original input behavior; removed forced POSIX newline insertion from rebuild_markdown_with_frontmatter_and_imports_ordered, rebuild_markdown_with_raw_frontmatter, and rebuild_markdown_content_only functions. Added 8+ unit tests covering save→reload trailing-newline preservation across various content types (with/without frontmatter, with MDX imports, with/without trailing newlines).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hop, hop—the newlines dance,
No forced appends in my stance,
What comes in shall go back out,
Round-trip tests remove the doubt!
Trailing whispers now preserved,

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The pull request title 'Fix editor Scroll Jump' does not align with the actual changes, which focus on fixing trailing newline behavior in markdown file parsing and reconstruction logic. Update the title to accurately reflect the main change, such as 'Fix trailing newline handling in markdown frontmatter parsing' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 92.31% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/editor-scroll-jump

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f44697 and 39b5881.

⛔ Files ignored due to path filters (1)
  • docs/tasks-done/task-2026-03-31-fix-editor-scroll-jump.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • src-tauri/src/commands/files.rs

Comment on lines +406 to 409
// 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');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

@dannysmith dannysmith merged commit dcd5396 into main Mar 31, 2026
8 checks passed
@dannysmith dannysmith deleted the fix/editor-scroll-jump branch March 31, 2026 04:20
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