我已经设法在 Angular 7 中设置了 ngx-quill,我需要创建一个自定义文本印迹,如下所示(简化):
... /*** Custom blot: [its editable text content] ***/ ...
我必须能够做到以下几点:
- 在创建和之后随时设置其可编辑内容
- 按回车键(只是在可编辑区域插入换行符),我不希望它分裂印迹或做任何复杂的魔法,我只想在该区域看到换行符
到目前为止我的自定义印迹:
/**
* REGISTER BLOT: CUSTOM
*/
var Embed = Quill.import('blots/embed');
class QuillBlotCustom extends Embed {
static blotName: string = 'cmd-custom';
static className: string = 'quill-cmd-custom';
static tagName: string = 'span';
static create(value: { cmd: any, ... }) {
let node = super.create(value);
const content = value.cmd.content ? value.cmd.content : '';
node.innerHTML = `<span>${value.cmd.prefix}${value.cmd.title}: <span contenteditable=true>${content}</span>${value.cmd.postfix}</span>`;
node.style.color = value.cmd.color;
node.style.backgroundColor = value.cmd.bgColor;
node.setAttribute('valueCmd', JSON.stringify(value.cmd));
node.addEventListener('keydown', function(e) {
// handling Enter key
if (e.keyCode === 13) {
e.preventDefault();
// HOW TO ACCESS QUILL INSTANCE FROM HERE?
}
});
setTimeout(() => {
return node;
}
static value(node) {
const val = {
cmd: JSON.parse(node.getAttribute('valueCmd')),
//text: node.firstElementChild.firstElementChild.firstElementChild.innerText,
node: node
};
val.cmd.content = node.firstElementChild.firstElementChild.firstElementChild.innerText
return val;
}
update(mutations: MutationRecord[], context: {[key: string]: any}) {
console.log('update');
}
}
Quill.register({
'formats/cmd-custom': QuillBlotCustom
});
我可以通过调用轻松创建具有任意内容的印迹
const cmd = ...;
this.quill.insertEmbed(range.index, 'cmd-custom', { cmd: cmd });
然后我被困在如何从这一点开始。
所以:
- 创建自定义印迹后如何更新其内容?
- 如何从自定义印迹的类中访问我的代码的任何部分(Quill 实例等)?
- 如何将 Enter 键的行为从退出可编辑区域更改为仅插入换行符并让用户继续输入?
每一个帮助表示赞赏!:)