Skip to content

fix: keep insert-at-end order for non-newline captures#1120

Merged
chhoumann merged 1 commit intomasterfrom
fix-insert-at-end-order-without-trailing-newline
Feb 24, 2026
Merged

fix: keep insert-at-end order for non-newline captures#1120
chhoumann merged 1 commit intomasterfrom
fix-insert-at-end-order-without-trailing-newline

Conversation

@chhoumann
Copy link
Copy Markdown
Owner

@chhoumann chhoumann commented Feb 24, 2026

Summary

  • fix a regression in insertAfter.insertAtEnd when the capture text does not end with a newline and the file has trailing EOF blank lines
  • avoid shifting insertion into trailing EOF blank lines for non-newline entries, preserving append order across repeated captures
  • keep existing spacing-preservation behavior for newline-terminated capture formats
  • add regression coverage for # H\nA\n\n + X then Y (no trailing newline), asserting order remains X then Y

Validation

  • bun run test -- src/formatters/captureChoiceFormatter-frontmatter.test.ts
  • bun run test
  • bun run lint
  • bun run build-with-lint
  • Obsidian CLI (vault=dev) repro check: # H\nA\n\n with format {{value}} now yields # H\nA\nX\nY after two captures

Open with Devin

Summary by CodeRabbit

  • Bug Fixes

    • Fixed insertion order preservation for repeated captures when content lacks trailing newlines, ensuring consistent behavior across successive operations.
  • Tests

    • Added test coverage verifying insertion order preservation when formatting has no trailing newline and end-of-file blanks are present.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
quickadd Ready Ready Preview Feb 24, 2026 7:02am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8bb8ed4 and dd59b6b.

📒 Files selected for processing (2)
  • src/formatters/captureChoiceFormatter-frontmatter.test.ts
  • src/formatters/captureChoiceFormatter.ts

📝 Walkthrough

Walkthrough

The changes add a test case for handling insertion order preservation when formats lack a trailing newline, and update the capture formatter logic to anchor insert positions based on the inserted text's newline status, ensuring consistent ordering across successive captures.

Changes

Cohort / File(s) Summary
Test Coverage
src/formatters/captureChoiceFormatter-frontmatter.test.ts
Added test case "preserves insertion order when format has no trailing newline and EOF blanks exist" to verify deterministic insertion order across successive format operations without trailing newlines.
Core Formatter Logic
src/formatters/captureChoiceFormatter.ts
Introduced insertedText parameter to findInsertAfterPositionAtSectionEnd() method; updated insertion positioning logic to anchor position when inserted text lacks trailing newline; replaced condition checking body.endsWith("\n") with fileContent.endsWith("\n").

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #1102: Modifies captureChoiceFormatter insertion logic to handle files without a trailing newline and adjust content anchoring at EOF.
  • PR #1054: Changes insert-after positioning logic in captureChoiceFormatter for EOF-newline behavior when computing insertion points.
  • PR #1119: Modifies findInsertAfterPositionAtSectionEnd() to preserve spacing and ordering at end-of-file conditions.

Suggested labels

released

Poem

🐰 When text gets caught and formats flow,
Order's what we need to know!
No trailing newline? We don't despair,
Our anchored positions place with care,
Insert by insert, side by side,
Deterministic is our pride! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main fix: preserving insertion order when using insert-at-end with captures that lack trailing newlines.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-insert-at-end-order-without-trailing-newline

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.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying quickadd with  Cloudflare Pages  Cloudflare Pages

Latest commit: dd59b6b
Status: ✅  Deploy successful!
Preview URL: https://eb2f0138.quickadd.pages.dev
Branch Preview URL: https://fix-insert-at-end-order-with.quickadd.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@chhoumann chhoumann merged commit e7cbbf2 into master Feb 24, 2026
5 checks passed
@chhoumann chhoumann deleted the fix-insert-at-end-order-without-trailing-newline branch February 24, 2026 07:06
github-actions Bot pushed a commit that referenced this pull request Mar 5, 2026
# [2.12.0](2.11.0...2.12.0) (2026-03-05)

### Bug Fixes

* **capture:** preserve canvas tab indentation on configured writes ([#1125](#1125)) ([0a1578e](0a1578e))
* disallow capture targets with .base extension ([cb39ed4](cb39ed4))
* **field-suggestions:** opt-in inline values from fenced code blocks ([#1128](#1128)) ([8597905](8597905))
* **gui:** preserve modal edit position during settings reload ([#1132](#1132)) ([11bda19](11bda19))
* **gui:** reduce ai settings modal reload churn ([#1134](#1134)) ([ae0f7a1](ae0f7a1))
* **gui:** reduce choice builder reload churn ([#1136](#1136)) ([818272a](818272a))
* **gui:** reduce macro settings modal reload churn ([#1135](#1135)) ([a1a6271](a1a6271))
* harden existing-tab matching and document issue workflow ([#1108](#1108)) ([7b12d3b](7b12d3b))
* make template path resolution deterministic ([3297d54](3297d54))
* normalize capture title for non-markdown targets ([964d672](964d672))
* preserve capture-format spacing for insert-at-end ([#1119](#1119)) ([8bb8ed4](8bb8ed4))
* preserve explicit capture target file extensions ([57e43ff](57e43ff))
* preserve insert-at-end order for non-newline captures ([#1120](#1120)) ([e7cbbf2](e7cbbf2))
* resolve template file-name paths without duplicate default folder ([7bfd41b](7bfd41b))
* resolve vault-relative template paths using root folders ([81216de](81216de))

### Features

* add AI request logging API and reduce assistant log noise ([#1110](#1110)) ([2c36800](2c36800))
* automate docs version snapshot during release ([#1111](#1111)) ([1571846](1571846))
* **capture:** fully support capture into canvas cards ([#1124](#1124)) ([a53f889](a53f889))
* **cli:** add native QuickAdd Obsidian CLI handlers ([#1129](#1129)) ([8102d47](8102d47))
* **format:** support mapped VALUE suggester display text ([#1127](#1127)) ([b8ec56c](b8ec56c))
* **macro:** add editor cursor navigation commands ([101d5f6](101d5f6))
* support .base template files for template choices ([11e6490](11e6490))

### Reverts

* **gui:** remove modal reload refactor series ([#1137](#1137)) ([3ba1a73](3ba1a73)), closes [#1136](#1136) [#1135](#1135) [#1134](#1134) [#1133](#1133) [#1132](#1132)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 5, 2026

🎉 This PR is included in version 2.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant