Fix:修复当节点文本内容为空时再次输入文本时文本样式丢失的问题
This commit is contained in:
parent
de6bd0c3ef
commit
5393e49a7a
@ -101,8 +101,8 @@ function createRichTextNode() {
|
|||||||
recoverText = true
|
recoverText = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (recoverText) {
|
let text = this.getData('text')
|
||||||
let text = this.getData('text')
|
if (recoverText && !isUndef(text)) {
|
||||||
// 判断节点内容是否是富文本
|
// 判断节点内容是否是富文本
|
||||||
let isRichText = checkIsRichText(text)
|
let isRichText = checkIsRichText(text)
|
||||||
// 样式字符串
|
// 样式字符串
|
||||||
|
|||||||
@ -238,17 +238,25 @@ class RichText {
|
|||||||
this.textEditNode.style.borderRadius = (node.height || 50) + 'px'
|
this.textEditNode.style.borderRadius = (node.height || 50) + 'px'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!node.getData('richText')) {
|
// 节点文本内容
|
||||||
// 还不是富文本的情况
|
const nodeText = node.getData('text')
|
||||||
let text = ''
|
// 是否是空文本
|
||||||
if (!isUndef(node.getData('text'))) {
|
const isEmptyText = isUndef(nodeText)
|
||||||
text = String(node.getData('text')).split(/\n/gim).join('<br>')
|
// 是否是非空的非富文本
|
||||||
}
|
const noneEmptyNoneRichText = !node.getData('richText') && !isEmptyText
|
||||||
|
// 如果是空文本,那么设置为丢失样式状态,否则输入不会带上样式
|
||||||
|
if (isEmptyText) {
|
||||||
|
this.lostStyle = true
|
||||||
|
}
|
||||||
|
if (noneEmptyNoneRichText) {
|
||||||
|
// 还不是富文本
|
||||||
|
let text = String(nodeText).split(/\n/gim).join('<br>')
|
||||||
let html = `<p>${text}</p>`
|
let html = `<p>${text}</p>`
|
||||||
this.textEditNode.innerHTML = this.cacheEditingText || html
|
this.textEditNode.innerHTML = this.cacheEditingText || html
|
||||||
} else {
|
} else {
|
||||||
|
// 已经是富文本
|
||||||
this.textEditNode.innerHTML =
|
this.textEditNode.innerHTML =
|
||||||
this.cacheEditingText || node.getData('text')
|
this.cacheEditingText || nodeText
|
||||||
}
|
}
|
||||||
this.initQuillEditor()
|
this.initQuillEditor()
|
||||||
document.querySelector('.ql-editor').style.minHeight = originHeight + 'px'
|
document.querySelector('.ql-editor').style.minHeight = originHeight + 'px'
|
||||||
@ -258,7 +266,7 @@ class RichText {
|
|||||||
this.focus(
|
this.focus(
|
||||||
isInserting || (selectTextOnEnterEditText && !isFromKeyDown) ? 0 : null
|
isInserting || (selectTextOnEnterEditText && !isFromKeyDown) ? 0 : null
|
||||||
)
|
)
|
||||||
if (!node.getData('richText')) {
|
if (noneEmptyNoneRichText) {
|
||||||
// 如果是非富文本的情况,需要手动应用文本样式
|
// 如果是非富文本的情况,需要手动应用文本样式
|
||||||
this.setTextStyleIfNotRichText(node)
|
this.setTextStyleIfNotRichText(node)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user