CKEditor 5 save selected text and set it again as selected after recover the content

痴心易碎 提交于 2019-12-10 18:18:34

问题


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?

Regards


回答1:


  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.

  2. 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



来源:https://stackoverflow.com/questions/51518889/ckeditor-5-save-selected-text-and-set-it-again-as-selected-after-recover-the-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!