From b28e7227e5b251ea99d18791170a7de5927d3578 Mon Sep 17 00:00:00 2001 From: Tarrency <760216236@qq.com> Date: Fri, 1 Nov 2024 00:34:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=8C=E5=87=BB=E6=96=87=E5=AD=97?= =?UTF-8?q?=E9=80=89=E4=B8=AD+=E9=94=AE=E4=B8=8B=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E5=8E=9F=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/TextEdit.js | 35 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/simple-mind-map/src/core/render/TextEdit.js b/simple-mind-map/src/core/render/TextEdit.js index cc0d7009..ea4292e7 100644 --- a/simple-mind-map/src/core/render/TextEdit.js +++ b/simple-mind-map/src/core/render/TextEdit.js @@ -43,7 +43,7 @@ export default class TextEdit { this.onKeydown = this.onKeydown.bind(this) // 节点双击事件 this.mindMap.on('node_dblclick', (node, e, isInserting) => { - this.show({ node, e, isInserting }) + this.show({ node, e, isInserting, isFromDbclick: true }) }) // 点击事件 this.mindMap.on('draw_click', () => { @@ -92,7 +92,7 @@ export default class TextEdit { }) this.mindMap.on('scale', this.onScale) // // 监听按键事件,判断是否自动进入文本编辑模式 - if (this.mindMap.opt.enableAutoEnterTextEditWhenKeydown) { + if (this.mindMap.opt.enableAutoEnterTextEditWhenKeydown || this.mindMap.opt.enableAutoEnterTextCoverWhenKeydown) { window.addEventListener('keydown', this.onKeydown) } this.mindMap.on('beforeDestroy', () => { @@ -123,6 +123,16 @@ export default class TextEdit { : 'removeEventListener' ]('keydown', this.onKeydown) } + if ( + opt.enableAutoEnterTextCoverWhenKeydown !== + lastOpt.enableAutoEnterTextCoverWhenKeydown + ) { + window[ + opt.enableAutoEnterTextCoverWhenKeydown + ? 'addEventListener' + : 'removeEventListener' + ]('keydown', this.onKeydown) + } }) } @@ -184,7 +194,8 @@ export default class TextEdit { node, isInserting = false, isFromKeyDown = false, - isFromScale = false + isFromScale = false, + isFromDbclick = false }) { // 使用了自定义节点内容那么不响应编辑事件 if (node.isUseCustomNodeContent()) { @@ -216,7 +227,8 @@ export default class TextEdit { rect, isInserting, isFromKeyDown, - isFromScale + isFromScale, + isFromDbclick } if (this.mindMap.richText) { this.mindMap.richText.showEditText(params) @@ -259,7 +271,7 @@ export default class TextEdit { } // 显示文本编辑框 - showEditTextBox({ node, rect, isInserting, isFromKeyDown, isFromScale }) { + showEditTextBox({ node, rect, isInserting, isFromKeyDown, isFromScale, isFromDbclick }) { if (this.showTextEdit) return const { nodeTextEditZIndex, @@ -339,6 +351,19 @@ export default class TextEdit { } this.textEditNode.style.zIndex = nodeTextEditZIndex this.textEditNode.innerHTML = textLines.join('
') + if(this.mindMap.opt.enableAutoEnterTextCoverWhenKeydown){ + this.textEditNode.innerHTML = '' + } + if(this.mindMap.opt.enableAutoSelectAllTextWhenDoubleClick && isFromDbclick){ + console.log('here') + this.textEditNode.innerHTML = textLines.join('
') + const selection = window.getSelection() + // selection.removeAllRanges() + const range = document.createRange() + range.selectNodeContents(this.textEditNode) + selection.addRange(range) + console.log('selection', selection) + } this.textEditNode.style.minWidth = rect.width + this.textNodePaddingX * 2 + 'px' this.textEditNode.style.minHeight = rect.height + 'px'