Skip to content

fix(editor): serialize copied rich selections as Markdown - #21529

Merged
nwparker merged 7 commits into
nwparker/markdown-betterfrom
stack-structure
Sep 19, 2026
Merged

nwparker merged 7 commits into
nwparker/markdown-betterfrom
stack-structure

Conversation

@nwparker

@nwparker nwparker commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22

ELI5

Copying a rich selection keeps Markdown formatting.

What Changed

Uses the Markdown serializer for clipboard text and wires it into editor copy handling. Adds clipboard and table-pipe coverage.

Why

Reuses the editor serializer instead of maintaining a separate clipboard formatter.

Linked Issue

Related to #9858; this stack is a partial compatibility improvement and does not close the full request.

Visual Proof

Hidden Electron copy check on fd0b481, rebuilt from this branch. Selected only the rendered paragraph; copy preserved bold and link Markdown, preserved HTML, excluded the heading, and left the document unchanged. The test uses an isolated ClipboardEvent/DataTransfer, not the system clipboard or native keyboard shortcut.

Formatted selection

Captured plain-text clipboard content:

A **bold** paragraph with a [link](https://example.com).

Testing

Exact clipboard layer fd0b481: 15 focused unit tests passed; hidden Electron copy flow passed twice. The new browser regression will be retained in the parent integration PR when this layer is folded into it.

Final stack bd17fae:

All launches used ORCA_BACKGROUND_LAUNCH=1. Paired-client coverage runs on macOS; live SSH/network failures and Windows/Linux Electron UI were not exercised. Latest CI reruns are separate from these local results.

Review

Low incremental risk: clipboard serialization. Depends on #21527.

Independent readiness reviews covered #21527 and #21531. Later preview/scanner findings were fixed with regressions. The fence tracker retains mixed-marker closers to match the installed parser; over-indented closers are rejected.

Remaining stack: #21565 → #21527 → #21529 → #21530 → #21531 → #21532. Retarget each next PR after squash-merging its base. #21553 is on main. #9858 remains open because full GFM compatibility is broader than this stack.

Agent skill upstream boundary

  • Not applicable; no skill-installer source is included.

Checklist

  • User-visible behavior and implementation rationale explained.
  • Automated checks recorded with their scope.
  • Cross-platform, SSH/folder-workspace, and source-data effects considered.
  • All CI checks have finished successfully on fd0b481 (PR Checks run 35416503335).

@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 — the rich Markdown editor now places Markdown source on the clipboard as text/plain rather than rendered visible text.

  • Clipboard plain text is Markdown. rich-markdown-editor-config.ts adds a clipboardTextSerializer to editorProps that resolves editorRef.current?.markdown and delegates to the new slice helper, returning '' when the manager is unavailable.
  • New slice→Markdown helper. serializeRichMarkdownSliceAsMarkdown serializes slice.content.toJSON() when it is an array (ProseMirror returns null for an empty fragment) and otherwise yields ''.
  • Empty-selection cut uses the same serializer. rich-markdown-clipboard-write.ts writes the serializer output as text/plain and falls back to visibleText when it is absent or empty, keeping the readback check consistent.
  • Tests. A helper unit test and a table-padding regression test for renderTableToCompactMarkdown's outlier clamp.

The fallback behavior is sound: ProseMirror's own copy path already does someProp('clipboardTextSerializer', …) || textBetween(…), so an empty serializer result degrades to the previous plain text, and non-empty selections (which defer to ProseMirror) pick up the same prop. Slices the markdown serializer can't render (a bare tableRow returns '') fall back to visibleText through the ||. Paste consumers prefer text/html, so no internal round trip regresses. pnpm tc:web and the three affected suites (29 tests) pass.

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

@nwparker

Copy link
Copy Markdown
Contributor Author

Readiness pass for the incremental clipboard layer at fd0b481: reviewed all eight checklist areas; no unresolved review threads or proven findings. No mobile-facing surface, remote wire, filesystem ownership, dependency, shell, or persisted-schema changes. Clipboard HTML metadata and write/readback-before-delete remain intact. Fifteen focused unit tests and two rebuilt hidden Electron copy runs passed; PR Checks run 35416503335 succeeded. Visual proof and exact clipboard output are in the description. This merge folds clipboard into #21527, not main; native OS clipboard shortcuts remain outside the hidden test scope.

@nwparker
nwparker merged commit f52b510 into nwparker/markdown-better Sep 19, 2026
29 of 30 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.

1 participant