【发布时间】:2019-01-30 06:48:53
【问题描述】:
我在屏幕上有两个编辑器,一个是只读的。我想要做的是允许用户从只读编辑器中选择内容并通过单击按钮将其粘贴到另一个的当前位置。 (逻辑可能会操纵文本,这是我不想使用系统剪贴板的原因之一。)
到目前为止,我拥有能够粘贴文本的功能,如下所示。 (我正在使用 Angular 包装器,它解释了 CKEditorComponent 参考的存在。
doPaste(pasteEvent: PasteEvent, editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
editor.model.change(writer => {
writer.insertText(pasteEvent.text, editor.model.document.selection.getFirstPosition() );
});
}
我无法从文档中找到如何提取所选文本。到目前为止我所拥有的是:
clickPasteSelectedPlain(editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
const selection = editor.model.document.selection;
console.log('clickPasteAll selection', selection);
console.log('clickPasteAll selectedcontent', editor.model.document.getSelectedContent);
}
选择似乎会根据编辑器视图中的选择而改变。 getSelectedContent 函数未定义。如何获取内容?
【问题讨论】:
-
我认为您可以使用this answer 提取选定的文本。
-
@oleq 我看到了那个答案,但我打了折扣,因为编辑器中没有 getSelection() 函数。至少在当前版本中没有。
标签: ckeditor5