我正在使用 Angular 和 ngx-quill。我有一个自定义工具栏按钮,它将插入具有某些属性的文本。我想在单击该文本时选择该文本。
这是我到目前为止所拥有的:
export class InsertDemographic extends Embed {
static blotName: string = "demographic";
static tagName: string = "span";
static className: string = "demographic";
static create(demographic: Demographic) {
let node = super.create();
node.setAttribute('data-demographic_id', demographic.id);
node.innerHTML = `[${demographic.name.replace(" ","_")}]`;
node.addEventListener("click", () => {
console.log(this);
/* const range = this.quill.getSelection(true);
this.quill.setSelection(range.index - 1, 1, 'user'); */
});
return node;
}
static value(node){
return {
name: node.textContent.replace(/[\[\]]/g,""),
id: node.dataset.demographic_id
} as Demographic;
}
}
我添加了一个单击事件侦听器,它应该获取当前的 quill 实例以获取和设置选择。注释代码可以工作,但我不知道如何获取 quill 实例!
目前,此代码位于与我的编辑器组件分开的文件中,该组件扩展了工具栏并映射了自定义图标等。这个位于组件外部的单独文件使得管理 quill 实例变得困难,不确定正确的方法是什么。