Skip to content

[Feature] Add a one-click "Copy code" button to code blocks in the Tiptap editor #3707

Closed as duplicate

Description

@SolunaCG

Is your feature request related to a problem? Please describe.

Currently, code blocks in OpenCloud's Tiptap-based Markdown/OCNote editor do not provide a dedicated button to copy their contents to the clipboard.

To copy a code snippet, users have to manually select the code and use Ctrl+C (or Cmd+C). This can be inconvenient, especially for longer or multiline code blocks, and increases the risk of accidentally including surrounding text.

Many modern editors and documentation platforms, including GitHub and ChatGPT, offer a small "Copy code" button directly within code blocks. This allows users to copy an entire snippet with a single click, without manually selecting its contents.

Adding this functionality would make working with code snippets in OpenCloud significantly more convenient.

Describe the solution you'd like

Add a small, dedicated "Copy code" button (clipboard icon) to every code block in the Tiptap editor.

Suggested behavior:

  • One-click copying: Clicking the button copies the entire code block to the clipboard without requiring any text selection.
  • Plain text: Only the raw code should be copied, without HTML formatting, Markdown code fences (```), or the programming language identifier.
  • Preserve formatting: Line breaks, indentation, whitespace, and special characters should be preserved exactly.
  • Visual integration: Position the button in the upper-right area of the code block, alongside the existing programming language selector, without interfering with it.
  • User feedback: After a successful copy operation, briefly display a confirmation such as "Copied!" or change the icon to a checkmark.
  • Accessibility: Provide an accessible label (e.g. "Copy code to clipboard"), keyboard accessibility, and an appropriate tooltip.
  • Read-only support: The button should also be available when viewing a document in read-only mode, since copying code does not require editing permissions.
  • Error handling: If clipboard access fails or is unavailable, provide appropriate feedback.

Ideally, the button should be consistently available for all code blocks, regardless of the selected programming language.

Expected behavior:

  1. Open a Markdown or OCNote document containing one or more code blocks.
  2. Locate the copy icon in the upper-right corner of a code block.
  3. Click the icon.
  4. The entire code snippet is copied to the clipboard as plain text.
  5. A short visual confirmation indicates that copying was successful.
  6. Paste the code into another application and verify that its original formatting is preserved.

Describe alternatives you've considered

The current workaround is to manually select the contents of a code block and copy them using Ctrl+C / Cmd+C or the browser's context menu.

While this works, it is less convenient and more error-prone, particularly with large code snippets.

Using the Markdown source view to copy code is another possibility, but it requires additional steps and does not provide the same convenience as a dedicated button.

A simple, integrated copy button would be a more user-friendly solution.

Additional context

Tiptap already provides a similar UI component

Tiptap offers an official Copy to Clipboard Button component:

https://tiptap.dev/docs/ui-components/components/copy-to-clipboard-button

According to the documentation, this component supports copying selected editor content or entire nodes, optional formatting preservation, and copy-success callbacks.

The documented UI component is React-based and part of Tiptap's Start plan, while OpenCloud uses Vue 3. Therefore, it may not be directly reusable. However, it provides a useful reference for the intended functionality and user experience.

A lightweight Vue implementation using the browser's Clipboard API could provide the required behavior without introducing an additional commercial dependency.

Activity

  1. JammingBen commented on Oct 13, 2026

    @JammingBen
    Member

    I'm closing this as a duplicate of opencloud-eu/web#3579.

  2. SolunaCG commented on Oct 13, 2026

    @SolunaCG
    Author

    Sorry, I missed the existing issue when searching! Thanks for pointing it out, and apologies for the duplicate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions