简体   繁体   中英

get copied content inside onCopy hook (plugin)

I am trying to get copied fragment into onCopy hook vainly.

I've been trying with the event.clipboardData...

const { clipboardData } = event;
const encoded = clipboardData.getData("application/x-slate-fragment");

But it seems as empty. I have also tried with the getEventTransfer utils. But it returns {type: 'unknow'}

Here is the CodeSandBox that I have been testing.

i think its not possible with the saltejs to get the fragment, if your will see the doucmentation as well https://docs.slatejs.org/v/v0.47/slate-react/utils#functions here as well they are asking to make the fragment first and then copy the data to it. So i think you could use JavaScript for it, if it helps, just a suggestion.

if you just want to get the copied text then try plain javascript inside onCopy function

const copied_text = window.getSelection().toString();

if your want to get the fragment of copied text use

event.target.outerHTML or event.target.innerHTML in onCopy function

if you want to create another copied fragment you can do

document.createRange().createContextualFragment(event.target.outerHTML)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM