Feat:非富文本模式下文本编辑支持粘贴带换行的文本
This commit is contained in:
parent
156c866bc1
commit
e04b680cdc
@ -1184,9 +1184,18 @@ export const handleInputPasteText = (e, text) => {
|
|||||||
// 去除格式
|
// 去除格式
|
||||||
text = getTextFromHtml(text)
|
text = getTextFromHtml(text)
|
||||||
// 去除换行
|
// 去除换行
|
||||||
text = text.replaceAll(/\n/g, '')
|
// text = text.replaceAll(/\n/g, '')
|
||||||
const node = document.createTextNode(text)
|
const textArr = text.split(/\n/g)
|
||||||
selection.getRangeAt(0).insertNode(node)
|
const fragment = document.createDocumentFragment()
|
||||||
|
textArr.forEach((item, index) => {
|
||||||
|
const node = document.createTextNode(item)
|
||||||
|
fragment.appendChild(node)
|
||||||
|
if (index < textArr.length - 1) {
|
||||||
|
const br = document.createElement('br')
|
||||||
|
fragment.appendChild(br)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
selection.getRangeAt(0).insertNode(fragment)
|
||||||
selection.collapseToEnd()
|
selection.collapseToEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user