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 { ElementType } from '../../../dataset/enum/Element'
|
||||||
import { IElement } from '../../../interface/Element'
|
import { IElement } from '../../../interface/Element'
|
||||||
import { IPasteOption } from '../../../interface/Event'
|
import { IPasteOption } from '../../../interface/Event'
|
||||||
import { getClipboardData, removeClipboardData } from '../../../utils/clipboard'
|
import {
|
||||||
|
getClipboardData,
|
||||||
|
getIsClipboardContainFile,
|
||||||
|
removeClipboardData
|
||||||
|
} from '../../../utils/clipboard'
|
||||||
import {
|
import {
|
||||||
formatElementContext,
|
formatElementContext,
|
||||||
getElementListByHTML
|
getElementListByHTML
|
||||||
@@ -104,13 +108,15 @@ export function pasteByEvent(host: CanvasEvent, evt: ClipboardEvent) {
|
|||||||
paste(evt)
|
paste(evt)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 优先读取编辑器内部粘贴板数据
|
// 优先读取编辑器内部粘贴板数据(粘贴板不包含文件时)
|
||||||
|
if (!getIsClipboardContainFile(clipboardData)) {
|
||||||
const clipboardText = clipboardData.getData('text')
|
const clipboardText = clipboardData.getData('text')
|
||||||
const editorClipboardData = getClipboardData()
|
const editorClipboardData = getClipboardData()
|
||||||
if (clipboardText === editorClipboardData?.text) {
|
if (clipboardText === editorClipboardData?.text) {
|
||||||
pasteElement(host, editorClipboardData.elementList)
|
pasteElement(host, editorClipboardData.elementList)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
removeClipboardData()
|
removeClipboardData()
|
||||||
// 从粘贴板提取数据
|
// 从粘贴板提取数据
|
||||||
let isHTML = false
|
let isHTML = false
|
||||||
|
|||||||
@@ -79,3 +79,15 @@ export function writeElementList(
|
|||||||
if (!text && !html && !elementList.length) return
|
if (!text && !html && !elementList.length) return
|
||||||
writeClipboardItem(text, html, zipElementList(elementList))
|
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