Repository navigation
fix(editor): preserve heading, table, and code editing behavior - #21530
Conversation
Reference links, footnotes, unsupported HTML, and oversized files park markdown edit tabs in Source mode with a banner, but the dedicated read-only preview was reachable only through a menu item and a shortcut. Add Preview to the view toggle and to the banner for exactly this case, reusing the existing preview tab instead of duplicating it.
There was a problem hiding this comment.
Important
Two correctness regressions in the new serializer / Enter paths — the fence chooser can emit a code block that does not re-parse to itself, and mid-heading Enter now preempts table navigation inside a cell. Details inline.
Reviewed changes
Reviewed the full 24-file diff for #21530 against stack-structure.
- Preview on rich-mode fallback:
editor-panel-render-model.tsnow classifies rich-mode eligibility for every renderable markdown edit tab (not just rich mode) and threadsrichModeFallsBackToSourceintogetEditorToggleModes, which adds apreviewoption;EditorPanel/EditorContent/EditorEditFileSurface/EditorPanelShellrouteonOpenMarkdownPreviewto a new "Open preview" action in the fallback banner. - Safe code fences: new
rich-markdown-code-block-markdown.tsoverrides the code block'srenderMarkdownto choose a backtick/tilde fence that does not collide with the body. - Mid-heading Enter: new
rich-markdown-heading-split.tssplits a heading at the caret and converts the trailing block to a paragraph. - Table cell line breaks:
extractRowsjoins multiple cell blocks with<br>instead of collapsing them to a space. - Wide code lines:
.rich-markdown-editor prepinswhite-space: pre !importantso code blocks scroll instead of wrapping. - Test-only coverage: clipboard serialization, code-span padding, HTML fence scanning, and source-reconciliation cases.
ℹ️ Nitpicks
CELL_LINE_SEPARATORinrich-markdown-table-markdown.ts:73-75—.join(SEP).split(SEP).join('\n')is effectively.join('\n'), so the sentinel adds a round trip without changing the result.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 042af5dfe5 (plus the 712d50d419 base merge) since the prior pullfrog review at 6afe452. Both prior findings are addressed and no new issues were found.
- Removed the unsaved-draft preview restriction:
editor-panel-render-model.tsdropshasUnsavedMarkdownDraftfrom both the toggle set andcanOpenPreviewToSide. The preview tab renderseditBuffers[previewSourceFileId] ?? fileContent.content(EditorContent.tsx:213) andopenMarkdownPreviewkeys the preview to the source file id, so the live draft is what is shown — the guard was protecting against content that never existed. - Fixed the fallback banner gate:
EditorPanelShell.tsx:166now gatesonOpenMarkdownPreviewonmodel.canShowMarkdownPreview(markdown-edit aware) instead of the HTML-onlycanOpenPreviewToSide, so the banner's "Open preview" button is reachable. - Regression coverage: the render-model test now requires
previewto remain available for an unsaved fallback draft, andEditorPanelShell.header.test.tsxasserts the shell exposes the Markdown preview action while the HTML side-preview flag is false.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
# Conflicts: # src/renderer/src/components/editor/rich-markdown-clipboard-serialization.test.ts
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 7687bb5 since the prior pullfrog review at 712d50d419. The delta is a base retarget plus merge — no PR-authored editor code changed, so all prior findings remain addressed.
- Retargeted onto
nwparker/markdown-fallback-preview: the PR's base moved fromnwparker/markdown-betterto the new #21575 branch, which absorbs the preview-fallback work (render-model eligibility, thepreviewtoggle option, the fallback banner action, and theEditorPanel/EditorContent/EditorPanelShellthreading). Those files drop out of this PR's diff. - Merged the new base into
stack-preview: bringsfa15a05c(preview from unsaved drafts) and themarkdown-fence-consumersfence/link fixes into the branch.git diff 3afdb0c..7687bb5 -- src/renderer/src/components/editortouches only base-ownedtiptap-marked-facade.tsandrich-markdown-save-reopen.test.ts, so the PR's own 15-file editor diff is unchanged and all prior findings still hold.
ℹ️ Stack description and body are stale
The PR body still says it "Adds … the preview fallback affordance" and lists the stack as #21527 (base main) → #21530 → #21531, but the fallback preview now lives in the base branch (#21575). This PR's authored surface is only the editor fixes, so the description no longer matches the diff. Worth refreshing before merge.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 965d460 since the previous review at 7687bb5. Another base merge, no PR-authored delta.
- Merged the advanced base branch:
8b33fe853c(fix(editor): retain CR line endings during save recovery) reachedstack-previewvianwparker/markdown-fallback-preview.git diff 7687bb5..965d460touches only base-ownedrich-markdown-source-reconcile.ts,rich-markdown-save-reopen.test.ts, and a newtests/e2e/markdown-link-label-save.spec.ts; the PR's 15-file editor diff is unchanged, so the prior review stands.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
# Conflicts: # src/renderer/src/components/editor/rich-markdown-clipboard-serialization.test.ts # src/renderer/src/components/editor/rich-markdown-code-span-padding.test.ts
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of e18041b400 since the prior pullfrog review at 965d46082e. The only new commit is a merge of the advanced base branch — no PR-authored editor code changed.
- Merged the advanced base branch:
f154eb43ca(fix(editor): preserve copied blocks and literal Markdown attributes) reachedstack-previewvianwparker/markdown-fallback-preview.git range-diff 39fe8762..965d460 60ebab83..e18041bshows every PR commit unchanged (=), andgit diff 965d460..e18041bmatchesf154eb43ca's 12-file set exactly, so the PR's own 15-file editor diff is unchanged and all prior findings remain addressed. - Base-owned overlap is coherent: two of the merged base files are also touched by this PR (
rich-markdown-clipboard-serialization.test.ts,rich-markdown-code-span-padding.test.ts). The PR's test additions already use the base's new APIs (serializeRichMarkdownSliceForClipboard, the 3-argrestoreCodeSpanPadding), so the merge composes cleanly.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 02b9654fcd since the review at e18041b400. The only new commit is another base-branch merge; no PR-authored code changed.
- Merged a further base advance:
bcf4aded0d(fix(editor): include fallback preview label in its PR layer) reachedstack-previewvianwparker/markdown-fallback-preview, adding only theeditor.richMarkdown.openPreviewkey toen.json.git range-diff 60ebab83..e18041b bcf4aded..02b9654fshows every PR commit unchanged (=), andgit diff e18041b..02b9654fis that single base-owned i18n file, so the PR's 15-file editor diff is unchanged.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 81f0180aad since the prior pullfrog review at 02b9654fcd. The only new commit is another merge of the advanced base branch — no PR-authored code changed, so all prior findings remain addressed.
- Merged the advanced base branch:
667ff6564f(perf(editor): scan fence lines without substring allocations) reachedstack-previewvianwparker/markdown-fallback-preview, fast-forwarding the base frombcf4aded0dto8157e9e148.git diff 02b9654..81f0180 --name-onlyis a single base-owned file,markdown-fence-scanner.ts, whose sticky-regex + index-loop rewrite (newconsumeRange) is behavior-preserving; the PR's own 15-file editor diff is byte-identical to the previously reviewed state.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — two small suggestions inline.
Reviewed changes
Incremental review of eb0e8fc7d6 since the prior pullfrog review at 81f0180aad. The only PR-authored commit in the delta is a one-file fix to the fence scanner; the rest of the 17-file diff is unchanged base content.
- Fence suffix whitespace:
hasClosingSuffixinmarkdown-fence-scanner.tsnow permits fence characters only before any whitespace in a closing-fence suffix, so a line like``` ~no longer closes a backtick fence — matchingmarked's closer rule. - Regression coverage:
markdown-scanner-boundaries.test.tsadds'``` ~'to the parser-parityit.eachover closing fences.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
The no-wrap choice is deliberate. Markdown code fences render as a preformatted block: line breaks, indentation, and long source lines stay intact, while the block provides horizontal scrolling. Wrapping is common as an optional editor preference, but it changes the visual shape of source lines and makes indentation-heavy code harder to scan and copy. The editor inherited |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 60f42817bb since the prior pullfrog review at eb0e8fc7d6. The delta is a two-file fence-scanner fix that addresses both prior inline suggestions; no new issues.
- Spaces-only closing suffix:
hasClosingSuffixinmarkdown-fence-scanner.tsnow treats only space (32) as suffix whitespace, so a tab- or CR-suffixed line no longer closes a fence — matchingmarked's{0,3}\1[~]* *(?=\n|$)` closer. - Dead branch removed: the redundant inner
if/return falseinhasClosingSuffixis collapsed to a singlereturn false. - Regression coverage: the parser-parity
it.eachover closing fences gains'```\t', which fails against the pre-fix code (a tab suffix used to close the fence whilemarkedkeeps it open).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — one minor test-coverage suggestion inline.
Reviewed changes
Incremental review of a08dc001e0 since the prior pullfrog review at 60f42817bb. The new commit skips the expensive HTML round-trip validation when the markdown editor is in source mode; the rest of the 21-file diff is unchanged.
- Source-mode fast path:
getMarkdownRichModeUnsupportedReasonacceptsvalidateHtmlRoundTrip(defaulttrue) and returns the cheap scanner'shtml-or-jsxreason immediately when it is false, so typing in source mode no longer builds a throwaway TipTap editor. - Wiring:
getEditorPanelRenderModelpassesvalidateHtmlRoundTrip: mdViewMode === 'rich', keeping the full round trip only where the rich editor decision actually depends on it. - Cache key extended:
getCachedMarkdownRichModeEligibilitynow keys entries onvalidateHtmlRoundTrip, so a conservative source-mode decision cannot be served to a rich-mode read of the same content. - Coverage: a new case spies on the HTML-validation and round-trip modules to assert neither runs when
validateHtmlRoundTripis false.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 2f28904bbf since the prior pullfrog review at a08dc001e0. The only new commit is test-only and pins the source-mode fast path flagged in the prior review; the rest of the 22-file diff is unchanged.
- Source-mode validation probe test:
editor-panel-render-model.test.tsrenders an HTML Markdown file withmarkdownViewMode: 'source'and spies ongetRichMarkdownHtmlValidationOutput/getRichMarkdownRoundTripOutput, asserting neither runs — covering thevalidateHtmlRoundTrip: mdViewMode === 'rich'wiring that previously had no test. Confirmed the case fails when the wiring is reverted to unconditional validation, so it is real coverage rather than a tautology.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Incremental review of 9e7f032902 since the prior pullfrog review at 2f28904bbf. The only new commit is test-only; no product code changed, and all prior findings remain addressed.
- Playwright-native selection in the copy-formatting spec:
tests/e2e/markdown-copy-formatting.spec.tsreplaces the hand-rolledcreateRange/selectNodeContents/addRange+ contenteditablefocus()+ synchronousselectionchangedispatch withlocator('p').selectText()andeditor.selectText(). Thewindow.getSelection()?.toString()polls still run before each copy, and the assertions (exact paragraph selection, exactcopiedBlocks,toContain('Copy formatting')) are unchanged, so the spec keeps the same teeth.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — one comment-accuracy nit inline.
Reviewed changes
Incremental review of e73483dbea since the prior pullfrog review at 9e7f032902. The only new commit is a single CSS hunk; the rest of the 23-file diff is unchanged and all prior findings remain addressed.
- Rich code blocks now wrap instead of scroll:
.rich-markdown-editor preswitchesoverflow-x: auto→overflow-x: hiddenandwhite-space: pre !important→white-space: pre-wrap !important, addingoverflow-wrap: anywhere, so long code lines wrap inside the block. This reverses the stack's earlier "keep wide code lines scrollable" behavior; the selector is scoped to the ProseMirror rich editor, and source mode (Monaco) is unaffected. - Rationale comment rewritten to contrast rich wrapping with source mode.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| padding: 14px 18px; | ||
| border-radius: 8px; | ||
| overflow-x: auto; | ||
| /* Rich editing favors readable lines; source mode keeps the raw text scrollable. */ |
There was a problem hiding this comment.
This rationale is inaccurate: markdown source mode renders MonacoEditor, whose wordWrap follows settings.editorWordWrap, which defaults to true (src/shared/default-global-settings.ts:55, buildFileEditorWordWrapOptions). Source mode therefore wraps long lines by default too — it does not keep the raw text scrollable unless the user turns word wrap off.
Technical details
# Correct the source-mode rationale comment
## Affected sites
- `src/renderer/src/assets/rich-markdown-editor.css:1005` — claims "source mode keeps the raw text scrollable".
- `src/renderer/src/components/editor/file-editor-word-wrap-options.ts:7` — `wordWrap: editorWordWrap === false ? 'off' : 'on'`.
- `src/shared/default-global-settings.ts:55` — `editorWordWrap: true`.
## Required outcome
- The comment should state that rich mode wraps for readability while the raw source view is a separate Monaco surface whose wrapping is user-configurable.
## Suggested approach (optional)
- Reword to avoid asserting source mode always scrolls.| /* Rich editing favors readable lines; source mode keeps the raw text scrollable. */ | |
| /* Rich editing wraps long code lines for readability; the raw source view is a separate Monaco surface. */ |
7167e3b
into
nwparker/markdown-fallback-preview

ELI5
Before this PR, a few normal rich-editor actions could change Markdown in surprising ways: Enter inside a table heading could bypass table navigation, saving fenced code could choose an unsafe fence, and multiple paragraphs in one table cell could collapse together. Long code lines also forced horizontal scrolling while editing.
What Changed
This PR keeps those edits round-trip safe: headings split only where the table handler should allow it, code fences are chosen so the saved block closes correctly, table-cell paragraphs retain line breaks, and rich-editor code lines wrap for readability. Raw source mode still preserves one-line scrolling.
Why
The rich editor converts Markdown into an editable document and converts it back when saving. The fixes make those conversions match what the user edited, while the CSS-only wrapping change improves readability without changing stored text.
Linked Issue
Related to #9858; does not complete full GFM support.
Visual Proof
Before: rich editing let a long code line run past the available width, so the user had to scroll horizontally to read it.
After: the same line wraps inside the code block. Whitespace, explicit newlines, and the saved Markdown remain unchanged.
Testing
Review
Low-to-medium incremental risk: limited editor commands and serialization behavior. Preview navigation is reviewed separately in #21575. Fresh CI is required after stack updates.
main → #21574 (fence consumers) → #21527 (parsing/saving) → #21575 (draft preview) → #21530 (editing commands) → #21531 (reconciliation).
Agent skill upstream boundary
Checklist