Fix:修复切换主题时节点样式没有随之切换的问题

This commit is contained in:
wanglin2
2023-06-20 16:29:54 +08:00
parent c8d2f284fd
commit f1355c9d2a
5 changed files with 55 additions and 4 deletions

View File

@@ -259,4 +259,24 @@ export const layoutValueList = [
CONSTANTS.LAYOUT.TIMELINE,
CONSTANTS.LAYOUT.TIMELINE2,
CONSTANTS.LAYOUT.FISHBONE
]
// 节点数据中非样式的字段
export const nodeDataNoStylePropList = [
'text',
'image',
'imageTitle',
'imageSize',
'icon',
'tag',
'hyperlink',
'hyperlinkTitle',
'note',
'expand',
'isActive',
'generalization',
'richText',
'resetRichText',
'uid',
'activeStyle'
]

View File

@@ -798,6 +798,11 @@ class Node {
getData(key) {
return key ? this.nodeData.data[key] || '' : this.nodeData.data
}
// 是否存在自定义样式
hasCustomStyle() {
return this.style.hasCustomStyle()
}
}
export default Node

View File

@@ -1,4 +1,4 @@
import { tagColorList } from '../../../constants/constant'
import { tagColorList, nodeDataNoStylePropList } from '../../../constants/constant'
const rootProp = ['paddingX', 'paddingY']
const backgroundStyleProps = ['backgroundColor', 'backgroundImage', 'backgroundRepeat', 'backgroundPosition', 'backgroundSize']
@@ -209,6 +209,17 @@ class Style {
node2.fill({ color: color })
fillNode.fill({ color: fill })
}
// 是否设置了自定义的样式
hasCustomStyle() {
let res = false
Object.keys(this.ctx.nodeData.data).forEach((item) => {
if (!nodeDataNoStylePropList.includes(item)) {
res = true
}
})
return res
}
}
Style.cacheStyle = null

View File

@@ -64,8 +64,18 @@ function createIconNode() {
function createRichTextNode() {
let g = new G()
// 重新设置富文本节点内容
if (this.nodeData.data.resetRichText || [CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) {
let recoverText = false
if (this.nodeData.data.resetRichText) {
delete this.nodeData.data.resetRichText
recoverText = true
}
if ([CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) {
// 如果自定义过样式则不允许覆盖
if (!this.hasCustomStyle()) {
recoverText = true
}
}
if (recoverText) {
let text = getTextFromHtml(this.nodeData.data.text)
this.nodeData.data.text = `<p><span style="${this.style.createStyleText()}">${text}</span></p>`
}

View File

@@ -219,7 +219,7 @@ class RichText {
underline: node.style.merge('textDecoration') === 'underline',
strike: node.style.merge('textDecoration') === 'line-through'
}
this.formatAllText(style)
this.pureFormatAllText(style)
}
// 获取当前正在编辑的内容
@@ -325,7 +325,7 @@ class RichText {
// 中文输入结束
onCompositionEnd() {
if (!this.showTextEdit) {
if (!this.showTextEdit || !this.lostStyle) {
return
}
this.isCompositing = false
@@ -372,6 +372,11 @@ class RichText {
// 格式化所有文本
formatAllText(config = {}) {
this.syncFormatToNodeConfig(config)
this.pureFormatAllText(config)
}
// 纯粹的格式化所有文本
pureFormatAllText(config = {}) {
this.quill.formatText(0, this.quill.getLength(), config)
}