copy-to-clipboard
copy-to-clipboard copied to clipboard
Accept a `style` parameter to specify the copied style.
If style parameter isn't specified, this forces a text/plain copy to make it easier to work with word processors.
This also changes the example code to exhibit the bug of issue #46 so
that it's easier to test.
Fixes #46
Also, as a quick note, I don't like the previous solution using a format property because I think it's not versatile enough. I don't think that copying text using whatever color the <body> has is what users would want...
ping @sudodoki, hey, do you think you'll be albe to look at this PR soon? I believe the previous solution 1/ doesn't provide much value, and 2/ doesn't fix the background issue in Chrome. And that this solution brings a much better value. Tell me what you think!
@julienw if this change is accepted what should user do if they don't want any style changes, yet want a rich text copied?
TBH, I think I'm slightly reluctant to merge this as this is a breaking change and 1) I'm still not 100% sold this is a right way to fix this, 2) currently I don't have too much time on my hands to deal with this. 🤷♂ Although your enthusiasm about this is inspiring.
The current situation is less than ideal because:
- it's kind of broken in chrome if there's a background color on the body (that's issue #46)
- specifying a format is broken in old IE (but maybe we don't mind much)
- it's possible to copy a rich text, but we don't control the style, and the behavior is different depending on the browser, so what's the point? I admit I really don't get it :-)
This 3rd point also answers your question if this change is accepted what should user do if they don't want any style changes, yet want a rich text copied?. I don't understand the use case.
I think this would work OK cross-browser only on a webpage that doesn't have its background set. As soon as the page has a background set the behavior will be different in Chrome vs Firefox (and probably others that I haven't tried). I personally think it's not a good thing.
That's why in this PR I added some code to force a white background and a black text color, so that we have some cross-browser consistency.
I guess I could try to keep the code using format so that it's not a breaking change anymore, and mark it clearly as "obsolete" so that we could remove it later. I can do that if you want to.