From d8fdc37684f7240c08adba9cc4194b8169e518ed 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: Fri, 5 Jan 2024 15:28:55 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=B8=90?= =?UTF-8?q?=E5=8F=98=E8=89=B2=E8=83=8C=E6=99=AF=E7=9A=84=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E7=BC=96=E8=BE=91=E6=97=B6=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=A1=86=E6=B2=A1=E6=9C=89=E5=BA=94=E7=94=A8=E6=B8=90?= =?UTF-8?q?=E5=8F=98=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 | 31 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index fe1ba8bb..2ef78439 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -218,18 +218,10 @@ class RichText { const targetNode = customInnerElsAppendTo || document.body targetNode.appendChild(this.textEditNode) } - // 使用节点的填充色,否则如果节点颜色是白色的话编辑时看不见 - let bgColor = node.style.merge('fillColor') - let color = node.style.merge('color') this.textEditNode.style.marginLeft = `-${paddingX * scaleX}px` this.textEditNode.style.marginTop = `-${paddingY * scaleY}px` this.textEditNode.style.zIndex = nodeTextEditZIndex - this.textEditNode.style.backgroundColor = - bgColor === 'transparent' - ? isWhite(color) - ? getVisibleColorFromTheme(this.mindMap.themeConfig) - : '#fff' - : bgColor + this.textEditNode.style.background = this.getBackground(node) this.textEditNode.style.minWidth = originWidth + paddingX * 2 + 'px' this.textEditNode.style.minHeight = originHeight + 'px' this.textEditNode.style.left = rect.left + 'px' @@ -279,6 +271,27 @@ class RichText { this.cacheEditingText = '' } + // 获取编辑区域的背景填充 + getBackground(node) { + const gradientStyle = node.style.merge('gradientStyle') + // 当前使用的是渐变色背景 + if (gradientStyle) { + const startColor = node.style.merge('startColor') + const endColor = node.style.merge('endColor') + return `linear-gradient(to right, ${startColor}, ${endColor})` + } else { + // 单色背景 + const bgColor = node.style.merge('fillColor') + const color = node.style.merge('color') + // 默认使用节点的填充色,否则如果节点颜色是白色的话编辑时看不见 + return bgColor === 'transparent' + ? isWhite(color) + ? getVisibleColorFromTheme(this.mindMap.themeConfig) + : '#fff' + : bgColor + } + } + // 如果是非富文本的情况,需要手动应用文本样式 setTextStyleIfNotRichText(node) { let style = {