feat: add inline insert-after capture mode#1063
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdds inline insertion support for capture choices by introducing Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI as CaptureChoiceBuilder
participant Formatter as CaptureChoiceFormatter
participant Editor as MarkdownView / FileOps
participant Error as ErrorUtils
User->>UI: Enable inline + configure target & replaceExisting
UI->>Formatter: Run insertAfter (inline = true)
rect rgb(220, 238, 255)
Note over Formatter: Inline insertion flow
Formatter->>Formatter: Validate target is single-line
alt target contains newline
Formatter->>Error: reportError("inline target contains newline")
Error->>User: show error
else target valid
Formatter->>Editor: search for targetString in fileContent
alt target found
alt replaceExisting = true
Formatter->>Editor: replace from target start to EOL with formatted capture
else
Formatter->>Editor: insert formatted capture immediately after target end (no newline)
end
else target not found
Formatter->>Formatter: determine createIfNotFound location
alt CREATE_IF_NOT_FOUND_CURSOR
Formatter->>Editor: insert at active editor cursor (error if no active editor)
else CREATE_IF_NOT_FOUND_TOP/BOTTOM
Formatter->>Editor: insert after frontmatter end / append to file end
end
end
end
end
Editor->>User: Document updated
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
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: 0
🧹 Nitpick comments (1)
src/formatters/captureChoiceFormatter.ts (1)
446-501: Consider adding a warning for unhandledcreateIfNotFoundLocationvalues.If
createIfNotFoundLocationis set to an unexpected value (not TOP, BOTTOM, or CURSOR), the function silently returns the unchanged file content. While unlikely in practice, logging a warning would aid debugging.🔎 Proposed improvement
} + // Unknown location - log warning and return unchanged + log.logWarning( + `Unknown createIfNotFoundLocation: ${this.choice.insertAfter.createIfNotFoundLocation}`, + ); return this.fileContent; }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/formatters/captureChoiceFormatter-frontmatter.test.tssrc/formatters/captureChoiceFormatter.tssrc/gui/ChoiceBuilder/captureChoiceBuilder.tssrc/types/choices/CaptureChoice.tssrc/types/choices/ICaptureChoice.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx,mts,mjs,js,json}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,mts,mjs,js,json}: Use tab indentation with width 2 in TypeScript and configuration files (enforced by Biome).
Follow an 80-character line guide (enforced by Biome).
Files:
src/types/choices/CaptureChoice.tssrc/types/choices/ICaptureChoice.tssrc/gui/ChoiceBuilder/captureChoiceBuilder.tssrc/formatters/captureChoiceFormatter-frontmatter.test.tssrc/formatters/captureChoiceFormatter.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Use camelCase for variables and functions in TypeScript.
Prefer type-only imports in TypeScript.
Files:
src/types/choices/CaptureChoice.tssrc/types/choices/ICaptureChoice.tssrc/gui/ChoiceBuilder/captureChoiceBuilder.tssrc/formatters/captureChoiceFormatter-frontmatter.test.tssrc/formatters/captureChoiceFormatter.ts
**/*.{ts,tsx,svelte}
📄 CodeRabbit inference engine (AGENTS.md)
Use PascalCase for classes and Svelte components.
Files:
src/types/choices/CaptureChoice.tssrc/types/choices/ICaptureChoice.tssrc/gui/ChoiceBuilder/captureChoiceBuilder.tssrc/formatters/captureChoiceFormatter-frontmatter.test.tssrc/formatters/captureChoiceFormatter.ts
src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Route logging through the
loggerutilities for consistent output.
Files:
src/types/choices/CaptureChoice.tssrc/types/choices/ICaptureChoice.tssrc/gui/ChoiceBuilder/captureChoiceBuilder.tssrc/formatters/captureChoiceFormatter-frontmatter.test.tssrc/formatters/captureChoiceFormatter.ts
🧬 Code graph analysis (3)
src/gui/ChoiceBuilder/captureChoiceBuilder.ts (1)
tests/obsidian-stub.ts (1)
Setting(151-233)
src/formatters/captureChoiceFormatter-frontmatter.test.ts (2)
src/types/choices/ICaptureChoice.ts (1)
ICaptureChoice(7-56)src/utils/errorUtils.ts (1)
reportError(99-120)
src/formatters/captureChoiceFormatter.ts (3)
src/utils/errorUtils.ts (1)
reportError(99-120)src/constants.ts (3)
CREATE_IF_NOT_FOUND_TOP(69-69)CREATE_IF_NOT_FOUND_BOTTOM(70-70)CREATE_IF_NOT_FOUND_CURSOR(71-71)tests/obsidian-stub.ts (1)
MarkdownView(346-353)
🔇 Additional comments (11)
src/types/choices/ICaptureChoice.ts (1)
38-39: LGTM!The new optional
inlineandreplaceExistingfields are well-typed and correctly marked as optional for backward compatibility with existing configurations.src/types/choices/CaptureChoice.ts (2)
26-27: LGTM!Constructor properly initializes the new fields to
false, matching the interface definition.Also applies to: 67-68
102-107: Consistent backward compatibility handling.The Load method correctly defaults
inlineandreplaceExistingtofalsewhen undefined, following the established pattern used forblankLineAfterMatchMode.src/formatters/captureChoiceFormatter.ts (3)
265-267: LGTM!Clean early-return pattern for inline mode, delegating to the specialized handler.
314-325: LGTM!The helper methods correctly detect linebreaks and handle CRLF line endings when determining end-of-line position.
327-370: LGTM!The inline handler correctly:
- Validates single-line targets and reports errors for multi-line
- Uses
indexOffor first-match semantics (aligned with test expectations)- Implements replace-to-EOL when
replaceExistingis enabled- Falls back to simple insertion otherwise
src/formatters/captureChoiceFormatter-frontmatter.test.ts (2)
41-44: LGTM!The
reportErrormock is properly set up to verify error handling paths in the inline insertion tests.
366-536: Good test coverage for inline insertion feature.The test suite covers the key scenarios:
- Basic inline insertion with suffix preservation
- Replace-to-EOL behavior
- Edge case when target is at end-of-line
- Create-if-not-found fallback
- Error reporting for missing targets
- First-match-only semantics
- Multi-line target validation
Consider adding tests for
createIfNotFoundLocationwith'bottom'and'cursor'values in a follow-up, though the current coverage is sufficient for the core functionality.src/gui/ChoiceBuilder/captureChoiceBuilder.ts (3)
442-444: LGTM!UI text updates from "line" to "text" are consistent and accurately reflect the inline insertion capability.
Also applies to: 467-467
491-524: LGTM!The inline insertion UI controls are well-structured:
- Defensive defaults for undefined values
- Conditional display of "Replace existing value" only when inline is enabled
reload()on inline toggle ensures dependent UI updates correctly
526-546: LGTM!The conditional disabling of section-based options (insert at end, blank line handling, consider subsections) when inline mode is active provides clear UX feedback. Descriptions appropriately update to explain why options are disabled.
Also applies to: 555-582, 584-615
|
🎉 This PR is included in version 2.10.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Testing
UI Changes
Related
Release Notes
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.