I am working on enabling rich text copy with CM (firepad).
I set CM option inputStyle: “contenteditable”
copy then calls function onCopyCut(e)
however this code then replaces the clipboard with a plain text version.
I need an option for this code not to run. I checked this by simply remarking:
//on(div, “copy”, onCopyCut);
//on(div, “cut”, onCopyCut);
indeed I get rich text copy working great !
I tried to do this with supplying my own onCopy with preventDefault but of course this totally disables copying.
Perhaps an option can be added like “allowrichtextcopy” that will prevent onCopyCut from running/ replacing the clipboard ? this will be quite elegant as the browser will be doing all the html copy work. I can’t see any way of doing that without changing CM code.
Alternatively though less elegant, exposing the ‘onCopyCut’ function so as to allow removeEventListener(‘copy’’, onCopyCut) on the display div ?
Also, as a side note, another thing I noticed is that function onCopyCut(e) uses: e.clipboardData.setData(“text/plain”
I think this is not legal according to the standard. https://html.spec.whatwg.org/multipage/interaction.html#dom-datatransfer-setdata says:
“If the DataTransfer object is no longer associated with a drag data store, abort these steps. Nothing happens”
As far as I can tell, as onCopyCut is not a darg&drop operation so this should not work, and the correct way to copy data to the clipboard should be with execCommand(‘copy’)