Fix:修复富文本编辑时删除完所有文本后再输入时样式丢失问题

This commit is contained in:
wanglin2
2023-06-11 22:21:03 +08:00
parent 97583ffcba
commit b33fd1908a

View File

@@ -41,6 +41,7 @@ class RichText {
this.node = null
this.styleEl = null
this.cacheEditingText = ''
this.lostStyle = false
this.initOpt()
this.extendQuill()
this.appendCss()
@@ -281,6 +282,20 @@ class RichText {
)
}
})
this.quill.on('text-change', () => {
let contents = this.quill.getContents()
let len = contents.ops.length
// 如果编辑过程中删除所有字符,那么会丢失主题的样式
if (len <= 0 || (len === 1 && contents.ops[0].insert === '\n')) {
this.lostStyle = true
// 需要删除节点的样式数据
this.syncFormatToNodeConfig(null, true)
} else if (this.lostStyle) {
// 如果处于样式丢失状态,那么需要进行格式化加回样式
this.setTextStyleIfNotRichText(this.node)
this.lostStyle = false
}
})
}
// 选中全部