Quill升级:修复粘贴文本时前后会出现换行多个换行,目前粘贴完还是会新开一行

This commit is contained in:
街角小林
2024-08-22 16:05:33 +08:00
parent 713d7b5844
commit dc27ca4ce8

View File

@@ -391,7 +391,7 @@ class RichText {
},
theme: 'snow'
})
// 拦截粘贴事件
// 拦截复制事件即Ctrl + c去除多余的空行
this.quill.root.addEventListener('copy', event => {
event.preventDefault()
const sel = window.getSelection()
@@ -455,16 +455,16 @@ class RichText {
}
})
// 拦截粘贴,只允许粘贴纯文本
this.quill.clipboard.addMatcher(Node.TEXT_NODE, node => {
let style = this.getPasteTextStyle()
return new Delta().insert(this.formatPasteText(node.data), style)
})
// this.quill.clipboard.addMatcher(Node.TEXT_NODE, node => {
// let style = this.getPasteTextStyle()
// return new Delta().insert(this.formatPasteText(node.data), style)
// })
this.quill.clipboard.addMatcher(Node.ELEMENT_NODE, (node, delta) => {
let ops = []
let style = this.getPasteTextStyle()
delta.ops.forEach(op => {
// 过滤出文本内容,过滤掉换行
if (op.insert && typeof op.insert === 'string' && op.insert !== '\n') {
if (op.insert && typeof op.insert === 'string') {
ops.push({
attributes: { ...style },
insert: this.formatPasteText(op.insert)