Skip to content

fix(editor): preserve heading, table, and code editing behavior - #21530

Merged
nwparker merged 41 commits into
nwparker/markdown-fallback-previewfrom
stack-preview
Sep 20, 2026
Merged

nwparker merged 41 commits into
nwparker/markdown-fallback-previewfrom
stack-preview

Conversation

@nwparker

@nwparker nwparker commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​367 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​337
Prod 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​163 $\color{#cf222e}{\Huge{\mathbf{−}}}$​38 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​125

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.

Before: rich editor code line scrolls

After: the same line wraps inside the code block. Whitespace, explicit newlines, and the saved Markdown remain unchanged.

After: rich editor code line wraps

Testing

  • 69 focused editor tests passed for rich-mode parsing, code-block behavior, highlighting, and save-safe editing.
  • Tests cover mid-heading/boundary Enter, table-owned Enter, modified shortcuts, embedded backticks/tildes, table paragraphs, and repeated code/emphasis saves.
  • The shared fence boundary follow-up adds tab-suffix parity coverage; 62 focused scanner/normalization/decoration tests pass.
  • Electron proof passed in headless mode with the rich editor rendered before and after the CSS change; typecheck and changed-code quality also pass.
  • TipTap CodeBlock source review confirms full whitespace preservation and text-based Markdown rendering; this CSS-only change does not alter saved Markdown.

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

  • Not applicable.

Checklist

  • ELI5, behavior, mechanism, rationale, and visual proof included.
  • Focused regression tests and cross-platform/remote impact reviewed.
  • Latest CI and Pullfrog review passed.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.ts now classifies rich-mode eligibility for every renderable markdown edit tab (not just rich mode) and threads richModeFallsBackToSource into getEditorToggleModes, which adds a preview option; EditorPanel / EditorContent / EditorEditFileSurface / EditorPanelShell route onOpenMarkdownPreview to a new "Open preview" action in the fallback banner.
  • Safe code fences: new rich-markdown-code-block-markdown.ts overrides the code block's renderMarkdown to choose a backtick/tilde fence that does not collide with the body.
  • Mid-heading Enter: new rich-markdown-heading-split.ts splits a heading at the caret and converts the trailing block to a paragraph.
  • Table cell line breaks: extractRows joins multiple cell blocks with <br> instead of collapsing them to a space.
  • Wide code lines: .rich-markdown-editor pre pins white-space: pre !important so code blocks scroll instead of wrapping.
  • Test-only coverage: clipboard serialization, code-span padding, HTML fence scanning, and source-reconciliation cases.

ℹ️ Nitpicks

  • CELL_LINE_SEPARATOR in rich-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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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.ts drops hasUnsavedMarkdownDraft from both the toggle set and canOpenPreviewToSide. The preview tab renders editBuffers[previewSourceFileId] ?? fileContent.content (EditorContent.tsx:213) and openMarkdownPreview keys 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:166 now gates onOpenMarkdownPreview on model.canShowMarkdownPreview (markdown-edit aware) instead of the HTML-only canOpenPreviewToSide, so the banner's "Open preview" button is reachable.
  • Regression coverage: the render-model test now requires preview to remain available for an unsaved fallback draft, and EditorPanelShell.header.test.tsx asserts the shell exposes the Markdown preview action while the HTML side-preview flag is false.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker changed the base branch from stack-structure to nwparker/markdown-better September 19, 2026 02:59
# Conflicts:
#	src/renderer/src/components/editor/rich-markdown-clipboard-serialization.test.ts
@nwparker
nwparker changed the base branch from nwparker/markdown-better to nwparker/markdown-fallback-preview September 19, 2026 03:24

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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 from nwparker/markdown-better to the new #21575 branch, which absorbs the preview-fallback work (render-model eligibility, the preview toggle option, the fallback banner action, and the EditorPanel/EditorContent/EditorPanelShell threading). Those files drop out of this PR's diff.
  • Merged the new base into stack-preview: brings fa15a05c (preview from unsaved drafts) and the markdown-fence-consumers fence/link fixes into the branch. git diff 3afdb0c..7687bb5 -- src/renderer/src/components/editor touches only base-owned tiptap-marked-facade.ts and rich-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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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) reached stack-preview via nwparker/markdown-fallback-preview. git diff 7687bb5..965d460 touches only base-owned rich-markdown-source-reconcile.ts, rich-markdown-save-reopen.test.ts, and a new tests/e2e/markdown-link-label-save.spec.ts; the PR's 15-file editor diff is unchanged, so the prior review stands.

Pullfrog  | View workflow run | Using 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
@nwparker nwparker changed the title fix(editor): improve Markdown editing and fallback preview fix(editor): preserve heading, table, and code editing behavior Sep 19, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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) reached stack-preview via nwparker/markdown-fallback-preview. git range-diff 39fe8762..965d460 60ebab83..e18041b shows every PR commit unchanged (=), and git diff 965d460..e18041b matches f154eb43ca'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-arg restoreCodeSpanPadding), so the merge composes cleanly.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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) reached stack-preview via nwparker/markdown-fallback-preview, adding only the editor.richMarkdown.openPreview key to en.json. git range-diff 60ebab83..e18041b bcf4aded..02b9654f shows every PR commit unchanged (=), and git diff e18041b..02b9654f is that single base-owned i18n file, so the PR's 15-file editor diff is unchanged.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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) reached stack-preview via nwparker/markdown-fallback-preview, fast-forwarding the base from bcf4aded0d to 8157e9e148. git diff 02b9654..81f0180 --name-only is a single base-owned file, markdown-fence-scanner.ts, whose sticky-regex + index-loop rewrite (new consumeRange) is behavior-preserving; the PR's own 15-file editor diff is byte-identical to the previously reviewed state.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ 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: hasClosingSuffix in markdown-fence-scanner.ts now permits fence characters only before any whitespace in a closing-fence suffix, so a line like ``` ~ no longer closes a backtick fence — matching marked's closer rule.
  • Regression coverage: markdown-scanner-boundaries.test.ts adds '``` ~' to the parser-parity it.each over closing fences.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

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 pre-wrap from the generic rich-text stylesheet, so this PR overrides that default only for code blocks and keeps overflow-x: auto as the viewport behavior.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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: hasClosingSuffix in markdown-fence-scanner.ts now treats only space (32) as suffix whitespace, so a tab- or CR-suffixed line no longer closes a fence — matching marked's {0,3}\1[~]* *(?=\n|$)` closer.
  • Dead branch removed: the redundant inner if/return false in hasClosingSuffix is collapsed to a single return false.
  • Regression coverage: the parser-parity it.each over closing fences gains '```\t', which fails against the pre-fix code (a tab suffix used to close the fence while marked keeps it open).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ 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: getMarkdownRichModeUnsupportedReason accepts validateHtmlRoundTrip (default true) and returns the cheap scanner's html-or-jsx reason immediately when it is false, so typing in source mode no longer builds a throwaway TipTap editor.
  • Wiring: getEditorPanelRenderModel passes validateHtmlRoundTrip: mdViewMode === 'rich', keeping the full round trip only where the rich editor decision actually depends on it.
  • Cache key extended: getCachedMarkdownRichModeEligibility now keys entries on validateHtmlRoundTrip, 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 validateHtmlRoundTrip is false.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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.ts renders an HTML Markdown file with markdownViewMode: 'source' and spies on getRichMarkdownHtmlValidationOutput / getRichMarkdownRoundTripOutput, asserting neither runs — covering the validateHtmlRoundTrip: 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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.ts replaces the hand-rolled createRange/selectNodeContents/addRange + contenteditable focus() + synchronous selectionchange dispatch with locator('p').selectText() and editor.selectText(). The window.getSelection()?.toString() polls still run before each copy, and the assertions (exact paragraph selection, exact copiedBlocks, toContain('Copy formatting')) are unchanged, so the spec keeps the same teeth.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ 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 pre switches overflow-x: auto → overflow-x: hidden and white-space: pre !important → white-space: pre-wrap !important, adding overflow-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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
Suggested change
/* 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. */

@nwparker
nwparker merged commit 7167e3b into nwparker/markdown-fallback-preview Sep 20, 2026
67 of 68 checks passed
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.

2 participants