Merge pull request #298 from nagisa77/codex/fix-paste-event-for-image-upload

Fix image paste event
This commit is contained in:
Tim
2025-08-01 02:10:05 +08:00
committed by GitHub

View File

@@ -162,9 +162,7 @@ export function createVditor(editorId, options = {}) {
input,
after
})
const container = document.getElementById(editorId)
if (container) {
container.addEventListener('paste', async (e) => {
const pasteHandler = async (e) => {
const items = e.clipboardData && e.clipboardData.items
if (!items) return
const files = []
@@ -182,7 +180,14 @@ export function createVditor(editorId, options = {}) {
vditor.tip(err)
}
}
})
}
const elements = []
if (vditor.wysiwyg) elements.push(vditor.wysiwyg.element)
if (vditor.ir) elements.push(vditor.ir.element)
if (vditor.sv) elements.push(vditor.sv.element)
elements.forEach(el => {
el.addEventListener('paste', pasteHandler)
})
return vditor
}