Ckeditor 5如何以编程方式触发复制,剪切和粘贴事件

时间:2018-12-28 09:18:24

标签: ckeditor5

我已经为ckeditor实现了右键单击菜单。我插入了Copy, Cut, Paste菜单项。我想触发ckeditor dom事件,并期待ckeditor侦听器捕获的事件。但是我不知道该怎么做。

我尝试运行editor.editing.view.document.fire('cut')。之后,在Clipboard.js中,触发了onCopyCut方法。但是data参数是undefined。如何发送数据参数以及应该发送什么数据参数?

1 个答案:

答案 0 :(得分:1)

You can't make pasting via a custom button possible. Basically, the access to the native copy/cut/paste actions is possible via the native document.execCommand() method:

document.execCommand( 'copy' );
document.execCommand( 'cut' );
document.execCommand( 'paste' );

However, only the copy and cut operations will work. Paste is blocked by the browsers for security reasons.

Therefore, the paste operation can only be triggered by the keystroke or a native "Paste" option (in the context menu or in the menu bar). You can't access the clipboard via your custom context menu today (it probably will change in some future). That's why CKEditor 5 does not override the native context menu (unlike e.g. CKEditor 4 or some other editors).

PS. In Google Docs, the custom "paste" button works (in Chrome) because Chrome comes with a Google Docs Addon preinstalled. It's a trick by Google to workaround the mentioned issue...