From cd7936a50be2f662b1dcba818a2fee3e0f89fe21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Thu, 11 Jan 2024 10:05:56 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=AF=8C=E6=96=87=E6=9C=AC=E7=BC=96=E8=BE=91=E6=97=B6?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E6=A0=B7=E5=BC=8F=E5=90=8E=E6=96=87=E5=AD=97?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=B8=A2=E5=A4=B1=E5=B9=B6=E4=B8=94=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E4=B8=BB=E9=A2=98=E4=B9=9F=E4=B8=8D=E4=BC=9A=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/RichText.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index 2ef78439..750be858 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -486,9 +486,9 @@ class RichText { } // 格式化当前选中的文本 - formatText(config = {}, clear = false) { + formatText(config = {}, clear = false, pure = false) { if (!this.range && !this.lastRange) return - this.syncFormatToNodeConfig(config, clear) + if(!pure) this.syncFormatToNodeConfig(config, clear) let rangeLost = !this.range let range = rangeLost ? this.lastRange : this.range clear @@ -501,7 +501,24 @@ class RichText { // 清除当前选中文本的样式 removeFormat() { + // 先移除全部样式 this.formatText({}, true) + // 再将样式恢复为当前主题改节点的默认样式 + const style = {} + if (this.node) { + ;[ + 'fontFamily', + 'fontSize', + 'fontWeight', + 'fontStyle', + 'textDecoration', + 'color' + ].forEach(key => { + style[key] = this.node.style.merge(key) + }) + } + const config = this.normalStyleToRichTextStyle(style) + this.formatText(config, false, true) } // 格式化指定范围的文本