microsoft / microsoft/monaco-editor
Copying non-syntax-highlighted plain text removes formatting
Nobody has claimed this yet.
- 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:

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:
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:

Copying and pasting now does include the formatting:
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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