Skip to content

Copy to clipboard without clipboard.js

Himanshu Kapoor requested to merge himkp-remove-clipboardjs into main

What does this MR do and why?

Use native navigator methods to copy plain text to the clipboard so that it can be pasted properly in the new rich text editor in GitLab.

Clipboard.js also copied HTML content alongside plain text, and it is hard to detect what to paste when using the rich text editor. When copying content from a <pre> tag, we only care about plain text, and the rich text should not be copied.

This change will allow people to copy examples from the Markdown docs page and paste directly in the rich text editor. This would fix gitlab#419106 (closed).

Browser support: https://caniuse.com/mdn-api_clipboard_writetext

Screenshots, screen recordings, or links to review app

No visible change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Configure a local GitLab Docs environment: https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/setup.md.
  2. Go to the markdown docs page.
  3. Copy a code block.
  4. Paste in plain text / rich text editor in gitlab.

Merge request acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Himanshu Kapoor

Merge request reports