fix: paste elements boundary error
This commit is contained in:
@@ -3,7 +3,11 @@ import { VIRTUAL_ELEMENT_TYPE } from '../../../dataset/constant/Element'
|
||||
import { ElementType } from '../../../dataset/enum/Element'
|
||||
import { IElement } from '../../../interface/Element'
|
||||
import { IPasteOption } from '../../../interface/Event'
|
||||
import { getClipboardData, removeClipboardData } from '../../../utils/clipboard'
|
||||
import {
|
||||
getClipboardData,
|
||||
getIsClipboardContainFile,
|
||||
removeClipboardData
|
||||
} from '../../../utils/clipboard'
|
||||
import {
|
||||
formatElementContext,
|
||||
getElementListByHTML
|
||||
@@ -104,13 +108,15 @@ export function pasteByEvent(host: CanvasEvent, evt: ClipboardEvent) {
|
||||
paste(evt)
|
||||
return
|
||||
}
|
||||
// 优先读取编辑器内部粘贴板数据
|
||||
// 优先读取编辑器内部粘贴板数据(粘贴板不包含文件时)
|
||||
if (!getIsClipboardContainFile(clipboardData)) {
|
||||
const clipboardText = clipboardData.getData('text')
|
||||
const editorClipboardData = getClipboardData()
|
||||
if (clipboardText === editorClipboardData?.text) {
|
||||
pasteElement(host, editorClipboardData.elementList)
|
||||
return
|
||||
}
|
||||
}
|
||||
removeClipboardData()
|
||||
// 从粘贴板提取数据
|
||||
let isHTML = false
|
||||
|
||||
@@ -79,3 +79,15 @@ export function writeElementList(
|
||||
if (!text && !html && !elementList.length) return
|
||||
writeClipboardItem(text, html, zipElementList(elementList))
|
||||
}
|
||||
|
||||
export function getIsClipboardContainFile(clipboardData: DataTransfer) {
|
||||
let isFile = false
|
||||
for (let i = 0; i < clipboardData.items.length; i++) {
|
||||
const item = clipboardData.items[i]
|
||||
if (item.kind === 'file') {
|
||||
isFile = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return isFile
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user