1
在我的應用程序,用戶可以在文檔身體的任何地方創建保證金的意見和評論錨定範圍內可以任意重疊,就像這樣:重疊內嵌註解與奎爾
This [abc]is a set of [xyz]overlapping[/xyz] comments[/abc]
我定義我的評論 - 錨定塗抹這樣的:
let Inline = Quill.import('blots/inline');
class CommentAnchorBlot extends Inline {
static create(commentId) {
let node = super.create();
node.setAttribute("class", "comment-anchor comment-anchor-" + commentId);
return node;
}
static formats(node) {
var classNames = node.getAttribute('class').split(/\s+/);
for (var i = 0, len = classNames.length; i < len; i++) {
var className = classNames[i];
if (className.indexOf("comment-anchor-") === 0) {
return className.replace("comment-anchor-", "");
}
}
return null;
}
}
CommentAnchorBlot.blotName = 'comment';
CommentAnchorBlot.className = 'comment-anchor';
CommentAnchorBlot.tagName = 'span';
Quill.register(CommentAnchorBlot);
但是,當我在一個運行實例奎爾測試它,它會產生羊皮紙是這樣的:
{
"ops" : [
{ "insert" : "This " },
{ "insert" : "is a set of ", "attributes" : { "comment" : "abc" } },
{ "insert" : "overlapping ", "attributes" : { "comment" : "xyz" } },
{ "insert" : " comments", "attributes" : { "comment" : "abc" } }
]
}
這是有問題的,因爲單詞「重疊」實際上應該同時具有「abc」和「xyz」作爲其註釋錨ID。
您會如何建議更改CommentAnchorBlot定義以適應此要求?在Quill文檔中,我還沒有看到任何其他例子的工作原理。
不錯!這看起來非常有希望......但是,當我使用此代碼時,評論ID類被添加到父塊(段落),而不是僅僅將當前選定的文本包裝在一個範圍中,我更喜歡這樣做......是否是否合理,還是我應該編寫代碼示例來重現問題? – benjismith
其實我覺得我只是打錯了範圍。它應該是INLINE_ATTRIBUTE而不是INLINE_ATTRIBUTOR。檢查是否有效?我將編輯帖子中的代碼。 – jhchen
完美。像現在的魅力一樣工作...再次感謝您的幫助!對此,我真的非常感激。 – benjismith