mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-17 22:08:25 +08:00
Merge pull request #1000 from Tarrency/switchtheme-fontcolor
fix: 解决切换主题前后,设置了部分字体样式的节点,其未设置的字体样式没有响应新主题样式的bug
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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>`
|
||||
|
||||
Reference in New Issue
Block a user