[英]get copied content inside onCopy hook (plugin)
I am trying to get copied fragment into onCopy
hook vainly.我试图将复制的片段徒劳地放入
onCopy
挂钩中。
I've been trying with the event.clipboardData...
我一直在尝试使用
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.我也尝试过使用
getEventTransfer
实用程序。 But it returns {type: 'unknow'}
但它返回
{type: 'unknow'}
Here is the CodeSandBox that I have been testing.这是我一直在测试的CodeSandBox 。
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.我认为用
saltejs
获取片段是不可能的,如果你也会看到文档 https://docs.slatejs.org/v/v0.47/slate-react/utils#functions他们也在问首先制作片段,然后将数据复制到它。 So i think you could use JavaScript for it, if it helps, just a suggestion.所以我认为你可以使用 JavaScript,如果有帮助,只是一个建议。
if you just want to get the copied text then try plain javascript inside onCopy
function如果您只想获取复制的文本,请在
onCopy
function 中尝试普通的 javascript
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
onCopy 中的
event.target.outerHTML
或event.target.innerHTML
onCopy function
if you want to create another copied fragment you can do如果你想创建另一个复制的片段,你可以这样做
document.createRange().createContextualFragment(event.target.outerHTML)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.