Skip to content

Normalise CRLF in replace_text before computing the diff - #1532

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h3884-replace-text-slide-notes-text-ad
Oct 30, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h3884-replace-text-slide-notes-text-ad

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/model/src/edit.rs:420-439 (replace_text), reached from crates/engine/src/cmd/slide.rs:556 (notes) (no existing issue): replace_text (slide.notes text) adds an empty paragraph when the new text uses CRLF line endings.

Cause

replace_text worked out the common prefix and suffix on the raw new text, and only insert turned CRLF into LF later. When the kept suffix started at the \n of a \r\n pair, the leftover \r was part of the inserted text and became an extra paragraph break, so "z\r\ny" gave "z\n\ny".

Fix

replace_text now turns \r\n and lone \r into \n before diffing, the same way TextBody::from_text does. A pair can no longer be split, and the same text with CRLF now leaves the body unchanged. A regression test covers CRLF at the suffix boundary, in the kept prefix and a lone CR.

Verified

  • Regression test edit::tests::replace_text_crlf_matches_from_text: fails on main without the fix and passes with it (cargo test -p deckcraft-model --lib replace_text_crlf_matches_from_text).
  • cargo xtask ci passes except backstage::tests::start_screen_opens_the_palette_and_preferences, which also fails on main without this change.

Not changed

insert and TextBody::from_text still do their own line-ending handling, and the text.set path is not changed.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Text replacements now handle Windows-style and classic Mac line endings consistently, preventing edits from splitting a line break.
    • Formatting is preserved when text is replaced, and text with equivalent line endings is treated as unchanged.

Found while testing crates/model/src/edit.rs:420-439 (replace_text), reached from crates/engine/src/cmd/slide.rs:556 (notes)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f893f6a and 9e5afc2.

Files selected for processing: 1
  • crates/model/src/edit.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Walkthrough

replace_text normalizes CRLF and lone CR line endings before comparing text. New tests cover normalized output, equivalent text, and retained formatting.

Changes: Text replacement

Layer / File(s) Summary
Normalize text and verify replacement behavior
crates/model/src/edit.rs
replace_text normalizes line endings before computing text differences. Tests check changed text, equivalent normalized text, and formatting on a preserved prefix.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: echelon

Merge Risk: Minimal · up to 9e5af

The change fixes the extra empty paragraph that appeared when notes were updated with CRLF line endings. A rare edge case remains for notes whose existing runs already contain a raw carriage return, where appended text could lose formatting on later runs. This is not a merge blocker.

Architecture risk: Medium · up to 9e5af

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/model/src/edit.rs: replace_text now normalizes CRLF and lone CR line endings before computing text differences.
  • observed — Modified behavior in crates/model/src/edit.rs: Added tests for CRLF handling in replace_text: changed text produces normalized paragraph breaks, already-normalized equivalent text leaves the body unchanged, and formatting remains on a preserved prefix.

Reliability and maintainability

  • inferred — Risk-relevant change factors for crates: blast_radius_2; direct_dependents_2
Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: replace_text now normalizes CRLF before computing the diff. The raw summary and PR objectives both describe this exact change in crates/model/src/edit.rs, so the title…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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 names the main change: replace_text now normalizes CRLF before computing the diff. The raw summary and PR objectives both describe this exact change in crates/model/src/edit.rs, so the title is fully related and specific.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. 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 1 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit c8d1a7c into storytold:main Oct 30, 2026
7 checks passed
@echelon

echelon commented Oct 30, 2026

Copy link
Copy Markdown
Member

Landed on main, thank you @Silvertree2010 for the contribution! If you haven't already, come join us on Discord: https://discord.gg/artcraft

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.

3 participants