Repository navigation
fix(editor): preserve Markdown source across rich edits - #23280
Conversation
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe rich Markdown editor now validates optional escape removal against parsed nodes and serializes a document that excludes a still-tracked synthetic trailing paragraph. Serialization commits can reconcile edited blocks with their original Markdown source. Shared marker-based matching is used by block tokenizers. The changes add unit, end-to-end, and opt-in benchmark tests for source fidelity, tokenizer behavior, and serialization performance. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to The normal test suite will fail until the expected search index is corrected. Fix the assertion before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The changes affect saved Markdown, but the new preservation path checks that its output reproduces the edited document and falls back when it cannot prove that. No introduced security issue was established; some security coverage remains incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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 |
|
@coderabbitai review Please review current head The docstring-coverage suggestion conflicts with this repository's AGENTS.md preference for concise, non-obvious comments only; please do not generate boilerplate documentation for coverage. |
|
@pullfrog Please review PR #23280 at current head |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 42b1a0cd-4db1-450c-9b08-1c88a672c14e
📒 Files selected for processing (12)
src/renderer/src/components/editor/markdown-directive-tokenizer.tssrc/renderer/src/components/editor/markdown-tokenizer-start.test.tssrc/renderer/src/components/editor/markdown-tokenizer-start.tssrc/renderer/src/components/editor/raw-markdown-html.tssrc/renderer/src/components/editor/rich-markdown-block-source-work.test.tssrc/renderer/src/components/editor/rich-markdown-block-source.tssrc/renderer/src/components/editor/rich-markdown-details-extension.tssrc/renderer/src/components/editor/rich-markdown-extensions.tssrc/renderer/src/components/editor/rich-markdown-save-benchmark.test.tssrc/renderer/src/components/editor/rich-markdown-table.test.tssrc/renderer/src/components/editor/rich-markdown-table.tssrc/renderer/src/components/editor/tiptap-marked-facade.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Full initial review at ab85fff. The PR fixes #22014 by stopping whole-document rewrites on the first rich edit, via three interlocking mechanisms:
- Synthetic trailing paragraph — StarterKit's
trailingNodeis disabled and replaced byRichMarkdownTrailingParagraph, which tracks the auto-inserted empty paragraph under a plugin key and strips it ingetRichMarkdownSerializationDocumentuntil edited. Stripping is gated on node identity (document.lastChild === synthetic), not on the mapping heuristic, so authored text cannot be dropped. - Block-source fallback —
reconcileRichMarkdownBlockSourcesplits baseline and current into top-level blocks, reuses exact source for equal blocks (boundeddiffArrays,maxEditLength: 256), and accepts the assembled result only whenparse(candidate).eq(liveDoc), which keeps it sound even if block/separator bookkeeping drifts. - Tokenizer/perf guardrails —
createMarkdownTokenizerStartregisters a marker per start fn thatRegistryLexer.blockTokensuses to skip absent-marker suffix scans; details directives are pre-checked withstartsWith; the table start slices to two lines before upstream's whole-suffix split; optional-escape omission is extended to~`*with per-block parser-equality proofs, and underscore unescape is restricted to intraword runs.
Verification this run: the new unit packet plus the pre-existing literal/reconcile/round-trip suites all pass (164 tests), and I confirmed the table-slice and marker-filter optimizations are behavior-preserving against the installed @tiptap/marked sources. A specialist trace of the trailing-paragraph invariant found no transaction sequence (undo/redo, paste, IME, setContent, block merge) that drops authored content.
ℹ️ Coordination with open PR #22425
#22425 (same author, still open) also adds src/renderer/src/components/editor/rich-markdown-escape-fidelity.test.ts and modifies rich-markdown-literal-serialization.ts, the same two files this PR adds/modifies. If both land, one will hit an add/add + edit conflict; whichever merges second should be rebased, and the other likely closed as superseded. Not a defect in this PR — flagging so merge order is deliberate.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
@coderabbitai review |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 3007d9456a (new since the prior pullfrog review at ab85fff).
- Case-insensitive
<details>start — the details HTML tokenizer'sstartchanges from the case-sensitivecreateMarkdownTokenizerStart('<details')(plainindexOf) toregisterMarkdownTokenizerStart('<', (source) => source.search(/<details\b/i)), so<Details>/<DETAILS>are located and clipped before the preceding paragraph can swallow them.matchDetailsHtmlBlockwas already/i, so the start was the only case-sensitive piece. - Reusable marker registration — the marker is now recorded via an exported
registerMarkdownTokenizerStart(marker, start);createMarkdownTokenizerStartdelegates to it. The facade's absent-marker skip stays sound:'<'is a superset of/<details\b/i, so a start is only dropped when no match is possible. - Tests — new
rich-markdown-details-case.test.ts(parses<details>/<Details>/<DETAILS>/<dEtAiLs>after prose as editable toggles) and a custom-marker case inmarkdown-tokenizer-start.test.ts; both pass (13 tests).
The broad '<' marker means the skip only engages for inputs with no < at all, but that matches the previous always-run behavior, so it is not a regression. No correctness, data-safety, or cross-platform concerns in the delta.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 96135c8e-b322-4b98-b8d4-99c6143349b4
📒 Files selected for processing (4)
src/renderer/src/components/editor/markdown-tokenizer-start.test.tssrc/renderer/src/components/editor/markdown-tokenizer-start.tssrc/renderer/src/components/editor/rich-markdown-details-case.test.tssrc/renderer/src/components/editor/rich-markdown-details-extension.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/editor/rich-markdown-details-extension.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 3007d9456a (new since the prior pullfrog review at ab85fff). Confirmed the case-insensitive <details> fix and its regression coverage.
- Case-insensitive
<details>start — the details tokenizer'sstartmoves from the case-sensitivecreateMarkdownTokenizerStart('<details')toregisterMarkdownTokenizerStart('<', (source) => source.search(/<details\b/i)). Previously the facade's absent-marker filter dropped the whole start function for<DETAILS>/<Details>inputs, so the preceding paragraph swallowed the tag; the new marker is retained whenever the input contains<. - Reusable marker registration —
registerMarkdownTokenizerStart(marker, start)is exported andcreateMarkdownTokenizerStartdelegates to it. The<marker is a superset of/<details\b/i, so the skip only engages when the input has no<at all, matching the prior always-run behavior. - Regression tests — new
rich-markdown-details-case.test.tsparses<details>/<Details>/<DETAILS>/<dEtAiLs>after prose as editable toggles, andmarkdown-tokenizer-start.test.tsgains a custom-marker skip case.
Verification this run: both focused suites pass (13 tests). I reverted the extension to the pre-fix start locally and confirmed 3 of 4 mixed/uppercase cases fail, then re-ran green with the fix restored. The start semantics also match marked's blockTokens contract — startBlock functions are invoked with e.slice(1), so 'Prose\n<DETAILS>' correctly yields index 5, which is what the new test asserts.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Editing a paragraph should change that paragraph, not add backslashes and blank lines to callouts elsewhere in the article.
What Changed
The rich editor now excludes the automatically inserted empty paragraph below a final quote/list from saved Markdown until it is edited. That convenience paragraph was changing the document on the first interaction and triggering a whole-document rewrite.
When character-level source reconciliation cannot preserve the file, a second path matches parsed blocks, reuses unchanged source and checks the assembled document against the live editor before accepting it. It preserves source across the existing 50,000-character cutoff and uses a bounded block diff with a per-editor source baseline.
Includes the safe-underscore/nested-callout work from #22425, adapted from @nvimq #22123, and extends parser-validated optional escaping to tildes, asterisks and backticks. Unsafe or unproven unescapes retain the original escaped output.
The performance follow-up removes an upstream table detector's whole-suffix split, skips searches for markers absent from each lexer input, and guards details directive tokenizers before their regexes. Source reconciliation no longer reparses every block individually; provisional token spans are still accepted only after the complete assembled document matches the live editor.
Why
Changing only the escape regex leaves the whole-document rewrite intact. Raising the old size cutoff leaves fuzzy patch failures intact. Tracking the editor-only paragraph and preserving proven-equal blocks addresses both triggers without guessing whether saved Markdown keeps its meaning.
Linked Issue
Fixes #22014. Includes #22425; that PR remains open and is not modified by this PR.
Visual Proof
The original hidden-app reproduction failed the exact saved-file assertion: editing the first paragraph removed the blank line after YAML and inserted blank quote lines in two untouched callouts. The same article and a >50,000-character variant now pass all three successive saves and reopen with only the typed changes. Screenshots show the reopened article; exact file assertions are the proof of source preservation, since escaped and unescaped Markdown often render identically.
Testing
I manually tested these changes locally (automated hidden Electron interaction and direct screenshot inspection on macOS).
Automated tests added/updated.
Full editor unit packet: 1,804 passed, 2 skipped. An opt-in save benchmark is separate from the CI correctness gates.
Ten hidden Electron tests passed after rebuilding: article and large-document exact save/reopen; literal/link save/reopen in git, folder and paired-remote workspaces; nested toggles and table-row editing.
Renderer typecheck, changed-code quality and diff whitespace checks passed.
Regression coverage includes CRLF, repeated blocks, insertion/deletion, authored blank paragraphs, code source, unsafe delimiters and trailing-paragraph editing/undo/redo.
Review
Source reuse is accepted only when parsing the assembled result gives the intended document. Failed proofs keep the existing canonical fallback. Block matching is bounded to 256 changes; only the current source baseline is retained. The synthetic paragraph remains visible and editable; authored empty paragraphs are retained.
Agent skill upstream boundary
Notes
No filesystem routing, remote protocol, keyboard mapping or platform-specific code changes. Paired remote and folder workflows were tested on macOS; native Windows/Linux, live SSH and mobile were not exercised locally. Performance was profiled and remeasured on the same synthetic documents. At 447,784 characters / 12,001 blocks, three successive save commits improved from 8,014/3,774/3,761 ms to 506/295/288 ms (about 94%/92%/92% faster). At 110,284 characters, saves measured 129/96/65 ms; at 36,284 characters, 39/37/34 ms. The stress case still costs roughly half a second on its first preservation pass, so these results do not claim zero renderer jank or cross-platform latency guarantees. Full assembled-document parsing remains linear work needed for the safety proof. Reproduce with
ORCA_BACKGROUND_LAUNCH=1 ORCA_MARKDOWN_SAVE_BENCHMARK=1 pnpm test src/renderer/src/components/editor/rich-markdown-save-benchmark.test.ts. Deterministic tests assert first-two-line table scanning, zero absent-marker suffix searches, nested lexer restoration and one full proof parse on repeated saves. This preserves callout source rather than adding a new styled alert node. Unsupported source boundaries retain the existing fallback.Checklist