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