Fix pasting images on web (#4670)

zio/stable
dan 2024-06-27 18:36:06 +01:00 committed by GitHub
parent 49396451ec
commit 58102377fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 8 deletions

View File

@ -152,23 +152,22 @@ export const TextInput = React.forwardRef(function TextInputImpl(
}, },
handlePaste: (view, event) => { handlePaste: (view, event) => {
const clipboardData = event.clipboardData const clipboardData = event.clipboardData
let preventDefault = false
if (clipboardData) { if (clipboardData) {
if (clipboardData.types.includes('text/html')) { if (clipboardData.types.includes('text/html')) {
// Rich-text formatting is pasted, try retrieving plain text // Rich-text formatting is pasted, try retrieving plain text
const text = clipboardData.getData('text/plain') const text = clipboardData.getData('text/plain')
// `pasteText` will invoke this handler again, but `clipboardData` will be null. // `pasteText` will invoke this handler again, but `clipboardData` will be null.
view.pasteText(text) view.pasteText(text)
preventDefault = true
}
getImageFromUri(clipboardData.items, (uri: string) => {
textInputWebEmitter.emit('photo-pasted', uri)
})
if (preventDefault) {
// Return `true` to prevent ProseMirror's default paste behavior. // Return `true` to prevent ProseMirror's default paste behavior.
return true return true
} else {
// Otherwise, try retrieving images from the clipboard
getImageFromUri(clipboardData.items, (uri: string) => {
textInputWebEmitter.emit('photo-pasted', uri)
})
} }
} }
}, },