Merge pull request #1000 from Tarrency/switchtheme-fontcolor

fix: 解决切换主题前后,设置了部分字体样式的节点,其未设置的字体样式没有响应新主题样式的bug
This commit is contained in:
街角小林
2024-11-12 18:34:53 +08:00
committed by GitHub
2 changed files with 28 additions and 6 deletions

View File

@@ -192,14 +192,15 @@ class Style {
}
// 生成内联样式
createStyleText() {
createStyleText(customStyle) {
const styles = {
color: this.merge('color'),
fontFamily: this.merge('fontFamily'),
fontSize: this.merge('fontSize'),
fontWeight: this.merge('fontWeight'),
fontStyle: this.merge('fontStyle'),
textDecoration: this.merge('textDecoration')
textDecoration: this.merge('textDecoration'),
...customStyle
}
return `
color: ${styles.color};
@@ -354,6 +355,17 @@ class Style {
return res
}
// 获取自定义的样式
getCustomStyle() {
let customStyle = {}
Object.keys(this.ctx.getData()).forEach(item => {
if (checkIsNodeStyleDataKey(item)) {
customStyle[item] = this.ctx.getData(item)
}
})
return customStyle
}
// hover和激活节点
hoverNode(node) {
const hoverRectColor =

View File

@@ -139,16 +139,18 @@ function createRichTextNode(specifyText) {
recoverText = true
}
if ([CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) {
// 如果自定义过样式则不允许覆盖
if (!this.hasCustomStyle()) {
// // 如果自定义过样式则不允许覆盖
// if (!this.hasCustomStyle() ) {
recoverText = true
}
// }
}
if (recoverText && !isUndef(text)) {
// 判断节点内容是否是富文本
let isRichText = checkIsRichText(text)
// 获取自定义样式
let customStyle = this.getCustomStyle()
// 样式字符串
let style = this.style.createStyleText()
let style = this.style.createStyleText(customStyle)
if (isRichText) {
// 如果是富文本那么线移除内联样式
text = removeHtmlStyle(text)
@@ -159,6 +161,14 @@ function createRichTextNode(specifyText) {
if (text === _text) {
text = addHtmlStyle(text, 'strong', style)
}
// 给strong添加样式没有成功则尝试给s标签添加样式
if (text === _text) {
text = addHtmlStyle(text, 's', style)
}
// 给s添加样式没有成功则尝试给em标签添加样式
if (text === _text) {
text = addHtmlStyle(text, 'em', style)
}
} else {
// 非富文本
text = `<p><span style="${style}">${text}</span></p>`