CKEditor 5保存选定的文本,并在恢复内容后再次将其设置为选定的文本 [英] CKEditor 5 save selected text and set it again as selected after recover the content

查看:305
本文介绍了CKEditor 5保存选定的文本,并在恢复内容后再次将其设置为选定的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用CKEditor 5进行开发,

I've been working around with the CKEditor 5 with:

var mySelection = editor.getSelection();

例如可以获取选定的文本并将其保存到数据库中。
我想知道是否有一种更简便的方法将所选文本保存到数据库,然后在恢复文本后将其设置为在编辑器窗口中自动选择的一种方法。

to get selected text and being able to save it to a database for example. I wanted to know if there is an easier way to save selected text to a database and then after recovering the text a way to set it as selected automatically in the editor window.

一种保存选择并在同一文本中再次设置选择的简便方法。
是否有插件或类似的东西?

An easy way to save selection and set selection again in the same text. Is there a plugin or something similar?

问候

推荐答案


  1. 这是获取所选内容的方法。您应该像做的那样得到一个选择,从中得到一个范围( .getFirstRange()),使用来作为(range.getItems( ))遍历范围内的所有项目,检查项目是否为文本节点( item.is('textProxy'))如果是,则将其数据添加到结果中( result = result + item.data )。这样,您就可以获取所选内容中的文本。

  1. This is the way to get stuff that is selected. You should get a selection as you did, get a range from it (.getFirstRange()), use for ( const item of range.getItems() ) to iterate through all the items in the range, check if an item is a text node (item.is( 'textProxy' )) and if it is, add it's data to the result (result = result + item.data). That way you can obtain the text inside the selection.

要在内容的一部分上恢复某些内容,您必须将模型范围保存在数据库中然后还原它并对其进行处理。可以,但是您需要保证内容不会在保存范围和内容之间变化(因此范围不会过时)。

To restore something on a part of a content, you would have to save the model range in the database and then restore it and do something with it. It is okay but you would need to guarantee that the content will not change between saving range and the content (so the range won't get outdated).

我不确定您要实现什么功能,但看起来您可以使用标记

I am not sure what feature are you trying to implement but it looks like you could use Markers

这篇关于CKEditor 5保存选定的文本,并在恢复内容后再次将其设置为选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆