Skip to content

Commit

Permalink
Fix non-text copying for Safari with -webkit-user-select: none. Add…
Browse files Browse the repository at this point in the history
…resses #75.
  • Loading branch information
lgarron committed Feb 9, 2018
1 parent 7a4c134 commit 4d250c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clipboard-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ function copyUsingTempSelection(e: HTMLElement, data: DT): boolean {
// rejected.
function copyUsingTempElem(data: DT): boolean {
var tempElem = document.createElement("div");
// Setting an individual property does not support `!important`, so we set the
// whole style instead of just the `-webkit-user-select` property.
tempElem.setAttribute("style", "-webkit-user-select: text !important");
// Place some text in the elem so that Safari has something to select.
tempElem.textContent = "temporary element";
document.body.appendChild(tempElem);
Expand Down
5 changes: 4 additions & 1 deletion test/manual/safari-user-select.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
}
function test() {
try {
clipboard.writeText("Safari user select test").then(
var dt = new clipboard.DT();
dt.setData("text/html", "<i>Markup</i> <b>text</b>. Paste me into a rich text editor.");
dt.setData("text/plain", "Fallback markup text. Paste me into a rich text editor.");
clipboard.write(dt).then("Safari user select test").then(
reportResult.bind(this, "PASS"),
function(e) {
reportResult("FAIL (after promise): ", e);
Expand Down

0 comments on commit 4d250c9

Please sign in to comment.