Skip to content

Editor: preserve markdown when copying and pasting - #3371

Merged
AlexAndBear merged 1 commit into
mainfrom
enhancement/markdown-clipboard-interoperability
Sep 16, 2026
Merged

AlexAndBear merged 1 commit into
mainfrom
enhancement/markdown-clipboard-interoperability

Conversation

@AlexAndBear

@AlexAndBear AlexAndBear commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Description

Add Markdown-aware clipboard handling to the rendered Markdown editor view.

Users can now copy rendered Markdown and paste it into Markdown-aware tools while keeping the Markdown syntax. Pasting Markdown back into the editor also works from tools like IntelliJ, even when they provide both text and HTML clipboard content.

For Markdown files we now prefer clipboard text over HTML. This means rich formatting copied from websites is not preserved unless it exists as Markdown syntax. Rich note editing should use .ocnote.

Related Issue

How Has This Been Tested?

  • test environment: local macOS workspace
  • test case 1: Markdown clipboard copy and paste unit tests
  • test case 2: related Markdown editor, frontmatter, and code block unit tests
  • test case 3: ESLint, TypeScript, and diff checks

Types of changes

  • Bugfix
  • Enhancement (a change that doesn't break existing code or deployments)
  • Breaking change (a modification that affects current functionality)
  • Technical debt (addressing code that needs refactoring or improvements)
  • Tests (adding or improving tests)
  • Documentation (updates or additions to documentation)
  • Maintenance (like dependency updates or tooling adjustments)

@AlexAndBear AlexAndBear self-assigned this Sep 14, 2026
@AlexAndBear
AlexAndBear force-pushed the enhancement/markdown-clipboard-interoperability branch 11 times, most recently from 591dcff to 8d24f77 Compare September 14, 2026 23:26

@JammingBen JammingBen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A paste of a single word or letter is always adding line breaks for some reason. E.g. have foobar in the editor, put the cursor after foo and paste a single letter. This results in 3 lines.

Comment on lines +26 to +28
// Let the original paste handler insert plain text inside code-like nodes.
// Parsing it as markdown would split pasted code into regular document blocks.
if (view.state.selection.$from.parent.type.spec.code) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably makes sense to guard inline code marks as well here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It looks like this is an error in the native paste command, we already return false here, but the issue persists.
This is also the case on demo

@AlexAndBear
AlexAndBear force-pushed the enhancement/markdown-clipboard-interoperability branch from 12b1df5 to 03a741b Compare September 16, 2026 02:27
@AlexAndBear

Copy link
Copy Markdown
Member Author

@JammingBen thanks for your review! Anyways, I decided to change the strategy entirely because we didn't use the native tip tap paste handler anymore and therefore we would need to care about a lot of quirks. So now we convert the pasted text to markdown and then let the the original paste handler take care.

Which unfortantly means, this PR needs a new review with a fresh eye 👁️

@AlexAndBear
AlexAndBear force-pushed the enhancement/markdown-clipboard-interoperability branch from 03a741b to 31c1fce Compare September 16, 2026 02:37
@AlexAndBear
AlexAndBear merged commit 8d4fddf into main Sep 16, 2026
31 checks passed
@AlexAndBear
AlexAndBear deleted the enhancement/markdown-clipboard-interoperability branch September 16, 2026 08:05
@openclouders openclouders mentioned this pull request Sep 16, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: copying and pasting markdown

2 participants