Skip to content

Commit

Permalink
Force a text/plain copy to make it easier to work with word processors
Browse files Browse the repository at this point in the history
  • Loading branch information
julienw committed Apr 4, 2019
1 parent 915a858 commit b8adc46
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ function copy(text, options) {
mark.style.msUserSelect = "text";
mark.style.userSelect = "text";
mark.addEventListener("copy", function(e) {
// Prevents the "copy" event from reaching the outside world.
e.stopPropagation();
// And force a text copy instead of an html copy, to make it easier to
// work with word processors.
e.preventDefault();
e.clipboardData.clearData();
e.clipboardData.setData('text/plain', text);
});

document.body.appendChild(mark);
Expand Down

0 comments on commit b8adc46

Please sign in to comment.