From be3faa0aef28c551f6e21962605c73137f9ecbfa 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: Wed, 6 Nov 2024 18:16:02 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=8C=89=E9=94=AE=E8=BF=9B=E5=85=A5=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=97=B6=E6=98=AF=E5=90=A6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B8=85=E7=A9=BA=E5=8E=9F=E6=9C=89=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/constants/defaultOptions.js | 2 ++ simple-mind-map/src/core/render/TextEdit.js | 9 +++++++-- simple-mind-map/src/plugins/RichText.js | 8 ++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index de76933e..04974fbf 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -130,6 +130,8 @@ export const defaultOpt = { // 是否在存在一个激活节点时,当按下中文、英文、数字按键时自动进入文本编辑模式 // 开启该特性后,需要给你的输入框绑定keydown事件,并禁止冒泡 enableAutoEnterTextEditWhenKeydown: false, + // 当enableAutoEnterTextEditWhenKeydown选项开启时生效,当通过按键进入文本编辑时是否自动清空原有文本 + autoEmptyTextWhenKeydownEnterEdit: false, // 自定义对剪贴板文本的处理。当按ctrl+v粘贴时会读取用户剪贴板中的文本和图片,默认只会判断文本是否是普通文本和simple-mind-map格式的节点数据,如果你想处理其他思维导图的数据,比如processon、zhixi等,那么可以传递一个函数,接受当前剪贴板中的文本为参数,返回处理后的数据,可以返回两种类型: /* 1.返回一个纯文本,那么会直接以该文本创建一个子节点 diff --git a/simple-mind-map/src/core/render/TextEdit.js b/simple-mind-map/src/core/render/TextEdit.js index cc0d7009..57773b7e 100644 --- a/simple-mind-map/src/core/render/TextEdit.js +++ b/simple-mind-map/src/core/render/TextEdit.js @@ -265,7 +265,8 @@ export default class TextEdit { nodeTextEditZIndex, textAutoWrapWidth, selectTextOnEnterEditText, - openRealtimeRenderOnNodeTextEdit + openRealtimeRenderOnNodeTextEdit, + autoEmptyTextWhenKeydownEnterEdit } = this.mindMap.opt if (!isFromScale) { this.mindMap.emit('before_show_text_edit') @@ -338,7 +339,11 @@ export default class TextEdit { this.textEditNode.style.background = this.getBackground(node) } this.textEditNode.style.zIndex = nodeTextEditZIndex - this.textEditNode.innerHTML = textLines.join('
') + if (isFromKeyDown && autoEmptyTextWhenKeydownEnterEdit) { + this.textEditNode.innerHTML = '' + } else { + this.textEditNode.innerHTML = textLines.join('
') + } this.textEditNode.style.minWidth = rect.width + this.textNodePaddingX * 2 + 'px' this.textEditNode.style.minHeight = rect.height + 'px' diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index f334eb2c..fbcd68ed 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -188,7 +188,8 @@ class RichText { textAutoWrapWidth, selectTextOnEnterEditText, transformRichTextOnEnterEdit, - openRealtimeRenderOnNodeTextEdit + openRealtimeRenderOnNodeTextEdit, + autoEmptyTextWhenKeydownEnterEdit } = this.mindMap.opt textAutoWrapWidth = node.hasCustomWidth() ? node.customTextWidth @@ -279,7 +280,10 @@ class RichText { if (isEmptyText) { this.lostStyle = true } - if (noneEmptyNoneRichText) { + if (isFromKeyDown && autoEmptyTextWhenKeydownEnterEdit) { + this.textEditNode.innerHTML = '' + this.lostStyle = true + } else if (noneEmptyNoneRichText) { // 还不是富文本 let text = String(nodeText).split(/\n/gim).join('
') let html = `

${text}

`