fix: 解决切换主题前后,设置了部分字体样式的节点,其未设置的字体样式没有响应新主题样式的bug
This commit is contained in:
parent
4e6688e4e0
commit
ad8cf74bba
@ -192,14 +192,15 @@ class Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 生成内联样式
|
// 生成内联样式
|
||||||
createStyleText() {
|
createStyleText(customStyle) {
|
||||||
const styles = {
|
const styles = {
|
||||||
color: this.merge('color'),
|
color: this.merge('color'),
|
||||||
fontFamily: this.merge('fontFamily'),
|
fontFamily: this.merge('fontFamily'),
|
||||||
fontSize: this.merge('fontSize'),
|
fontSize: this.merge('fontSize'),
|
||||||
fontWeight: this.merge('fontWeight'),
|
fontWeight: this.merge('fontWeight'),
|
||||||
fontStyle: this.merge('fontStyle'),
|
fontStyle: this.merge('fontStyle'),
|
||||||
textDecoration: this.merge('textDecoration')
|
textDecoration: this.merge('textDecoration'),
|
||||||
|
...customStyle
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
color: ${styles.color};
|
color: ${styles.color};
|
||||||
@ -354,6 +355,17 @@ class Style {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取自定义的样式
|
||||||
|
getCustomStyle() {
|
||||||
|
let customStyle = {}
|
||||||
|
Object.keys(this.ctx.getData()).forEach(item => {
|
||||||
|
if (checkIsNodeStyleDataKey(item)) {
|
||||||
|
customStyle[item] = this.ctx.getData(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return customStyle
|
||||||
|
}
|
||||||
|
|
||||||
// hover和激活节点
|
// hover和激活节点
|
||||||
hoverNode(node) {
|
hoverNode(node) {
|
||||||
const hoverRectColor =
|
const hoverRectColor =
|
||||||
|
|||||||
@ -139,16 +139,18 @@ function createRichTextNode(specifyText) {
|
|||||||
recoverText = true
|
recoverText = true
|
||||||
}
|
}
|
||||||
if ([CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) {
|
if ([CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) {
|
||||||
// 如果自定义过样式则不允许覆盖
|
// // 如果自定义过样式则不允许覆盖
|
||||||
if (!this.hasCustomStyle()) {
|
// if (!this.hasCustomStyle() ) {
|
||||||
recoverText = true
|
recoverText = true
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
if (recoverText && !isUndef(text)) {
|
if (recoverText && !isUndef(text)) {
|
||||||
// 判断节点内容是否是富文本
|
// 判断节点内容是否是富文本
|
||||||
let isRichText = checkIsRichText(text)
|
let isRichText = checkIsRichText(text)
|
||||||
|
// 获取自定义样式
|
||||||
|
let customStyle = this.getCustomStyle()
|
||||||
// 样式字符串
|
// 样式字符串
|
||||||
let style = this.style.createStyleText()
|
let style = this.style.createStyleText(customStyle)
|
||||||
if (isRichText) {
|
if (isRichText) {
|
||||||
// 如果是富文本那么线移除内联样式
|
// 如果是富文本那么线移除内联样式
|
||||||
text = removeHtmlStyle(text)
|
text = removeHtmlStyle(text)
|
||||||
@ -159,6 +161,14 @@ function createRichTextNode(specifyText) {
|
|||||||
if (text === _text) {
|
if (text === _text) {
|
||||||
text = addHtmlStyle(text, 'strong', style)
|
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 {
|
} else {
|
||||||
// 非富文本
|
// 非富文本
|
||||||
text = `<p><span style="${style}">${text}</span></p>`
|
text = `<p><span style="${style}">${text}</span></p>`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user