microsoft / microsoft/monaco-editor

Copying non-syntax-highlighted plain text removes formatting

Open
#2,194 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

editor-clipboard feature-request
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

monaco-editor version: 0.21.2 (whatever is in the playground)
Browser: Firefox 81.0.2
OS: Mac OS X 10.14.6
Playground code that reproduces the issue:

// The Monaco Editor can be easily created, given an
// empty container and an options literal.
// Two members of the literal are "value" and "language".
// The editor takes the full size of its container.

monaco.editor.create(document.getElementById("container"), {
	value: "function hello() {\n\talert('Hello world!');\n}",
	language: "plain/text"
});

This is the playground "Hello world!" with language changed to plain/text.

Appearance of the text in the editor in the browser is plain text style:

image

Copy and paste the text into a rich text editor e.g. Microsoft Outlook's New Mail window, and it gets copied as text only, with no formatting:

image

Switch the language to something with syntax highlighting, like the original playground example of "javascript" and the result is:

Text in the editor in the browser:

image

Copying and pasting now does include the formatting:

image

I think there's something specific to the Monaco editor that is generating this effect, because outside the editor, if I copy a plain text file opened in the browser, and paste that, there is formatting: it appears as something like Courier New when pasted into the rich text editor, even though that isn't the default font.

Expected behaviour: copying includes the formatting regardless of whether there is syntax highlighting or not.
Actual behaviour: copying only includes the formatting if syntax highlighting is working.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Monaco Editor playground reproduction, comparing copy and paste behavior for plain/text and javascript in Firefox. Investigate the editor's clipboard behavior from that entry point; done means copying plain text preserves formatting when pasted into a rich text editor, as syntax-highlighted text does.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.