我想在Quill文档中实现瞬态突出显示。
例如,设想一个SEARCH按钮,用户可以通过设置匹配文本范围的文本颜色来突出显示当前文档中关键字的所有实例。
今天我能做到这一点,有这样的事情:
var keyword = "hello"; var text = quill.getText(); var matchIndex = text.indexOf(keyword); while (matchIndex >= 0) { quill.formatText(matchIndex, keyword.length, { "color" : "#f00" }); matchIndex = text.indexOf(keyword, matchIndex + keyword.length); }但我不希望将得到的增量纳入本文件的官方变更历史。 这些只是短暂的亮点,我希望能够用这样的东西清除它们......
quill.clearTransientFormats();我甚至想让用户选择启用瞬态高亮显示,同时他们继续使用自己的破坏性更改来编辑和修改文档。
基本上,我想要两种不同的格式:
破坏性格式始终记录在文档历史记录中持久存在的增量序列中。 在文档历史记录中忽略瞬态格式,因为它仅适用于当前视图。实现这样的事情的最佳方法是什么?
I'd like to implement transient highlighting in a Quill document.
For example, imagine a SEARCH button where the user can highlight all instances of a keyword in the current document, by setting the text color for matching text ranges.
I can do that today, with something like this:
var keyword = "hello"; var text = quill.getText(); var matchIndex = text.indexOf(keyword); while (matchIndex >= 0) { quill.formatText(matchIndex, keyword.length, { "color" : "#f00" }); matchIndex = text.indexOf(keyword, matchIndex + keyword.length); }But I don't want the resultant deltas to be incorporated into the official change history of this document. These are just transient highlights, and I'd like to be able to clear them all away with something like this...
quill.clearTransientFormats();I'd even like to give the user the choice of leaving the transient highlights enabled, while they continue to edit and modify the document with their own destructive changes.
Essentially, I want to have two different kinds of formatting:
Destructive formatting is always recorded in the sequence of deltas persisted in the document history. Transient formatting is ignored in the document history, since it only applies to the current view.What's the best way to implement something like this?
最满意答案
我建议在保存之前对delta进行后处理。 使用compose可以很容易地实现:
var length = aboutToBeStored.length(); var toStore = aboutToBeStored.compose(new Delta().retain(0, length, { color: null }));I would recommend just post-processing the delta before saving. It can be achieved fairly easily with compose:
var length = aboutToBeStored.length(); var toStore = aboutToBeStored.compose(new Delta().retain(0, length, { color: null }));更多推荐
发布评论