Demo:代码优化

This commit is contained in:
wanglin2 2023-12-29 22:04:56 +08:00
parent 0cfa21d4e6
commit 1bb7e431fb
4 changed files with 8 additions and 30 deletions

View File

@ -287,7 +287,7 @@ onPaste(e) {
if (!selection.rangeCount) return
selection.deleteFromDocument()// 删除当前选区,也就是如果当前用户在输入框中选择了一些文本,会被删除
// 从剪贴板里取出文本数据
let text = (e.clipboardData || window.clipboardData).getData('text')
let text = e.clipboardData.getData('text')
// 调用库提供的getTextFromHtml方法去除格式
text = getTextFromHtml(text)
// 去除换行

View File

@ -237,7 +237,7 @@ mindMap.execCommand(<span class="hljs-string">&#x27;INSERT_CHILD_NODE&#x27;</spa
<span class="hljs-keyword">if</span> (!selection.rangeCount) <span class="hljs-keyword">return</span>
selection.deleteFromDocument()<span class="hljs-comment">// </span>
<span class="hljs-comment">// </span>
<span class="hljs-keyword">let</span> text = (e.clipboardData || <span class="hljs-built_in">window</span>.clipboardData).getData(<span class="hljs-string">&#x27;text&#x27;</span>)
<span class="hljs-keyword">let</span> text = e.clipboardData.getData(<span class="hljs-string">&#x27;text&#x27;</span>)
<span class="hljs-comment">// getTextFromHtml</span>
text = getTextFromHtml(text)
<span class="hljs-comment">// </span>

View File

@ -41,9 +41,9 @@ import { mapState } from 'vuex'
import {
nodeRichTextToTextWithWrap,
textToNodeRichTextWithWrap,
getTextFromHtml,
createUid,
htmlEscape
htmlEscape,
handleInputPasteText
} from 'simple-mind-map/src/utils'
//
@ -212,18 +212,7 @@ export default {
//
onPaste(e) {
e.preventDefault()
const selection = window.getSelection()
if (!selection.rangeCount) return
selection.deleteFromDocument()
let text = (e.clipboardData || window.clipboardData).getData('text')
//
text = getTextFromHtml(text)
//
text = text.replaceAll(/\n/g, '')
const node = document.createTextNode(text)
selection.getRangeAt(0).insertNode(node)
selection.collapseToEnd()
handleInputPasteText(e)
},
// key

View File

@ -52,10 +52,10 @@ import { mapState, mapMutations } from 'vuex'
import {
nodeRichTextToTextWithWrap,
textToNodeRichTextWithWrap,
getTextFromHtml,
createUid,
simpleDeepClone,
htmlEscape
htmlEscape,
handleInputPasteText
} from 'simple-mind-map/src/utils'
import { storeData } from '@/api'
@ -211,18 +211,7 @@ export default {
//
onPaste(e) {
e.preventDefault()
const selection = window.getSelection()
if (!selection.rangeCount) return
selection.deleteFromDocument()
let text = (e.clipboardData || window.clipboardData).getData('text')
//
text = getTextFromHtml(text)
//
text = text.replaceAll(/\n/g, '')
const node = document.createTextNode(text)
selection.getRangeAt(0).insertNode(node)
selection.collapseToEnd()
handleInputPasteText(e)
},
// key