Prevent rich-formatting paste (#4327)
* fix: prevent rich-formatting paste * fix: return true instead of preventDefaultzio/stable
parent
ebd4f93b9c
commit
247af5aee9
|
@ -150,16 +150,27 @@ export const TextInput = React.forwardRef(function TextInputImpl(
|
||||||
attributes: {
|
attributes: {
|
||||||
class: modeClass,
|
class: modeClass,
|
||||||
},
|
},
|
||||||
handlePaste: (_, event) => {
|
handlePaste: (view, event) => {
|
||||||
const items = event.clipboardData?.items
|
const clipboardData = event.clipboardData
|
||||||
|
|
||||||
if (items === undefined) {
|
if (clipboardData) {
|
||||||
return
|
if (clipboardData.types.includes('text/html')) {
|
||||||
|
// Rich-text formatting is pasted, try retrieving plain text
|
||||||
|
const text = clipboardData.getData('text/plain')
|
||||||
|
|
||||||
|
// `pasteText` will invoke this handler again, but `clipboardData` will be null.
|
||||||
|
view.pasteText(text)
|
||||||
|
|
||||||
|
// Return `true` to prevent ProseMirror's default paste behavior.
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
// Otherwise, try retrieving images from the clipboard
|
||||||
|
|
||||||
|
getImageFromUri(clipboardData.items, (uri: string) => {
|
||||||
|
textInputWebEmitter.emit('photo-pasted', uri)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getImageFromUri(items, (uri: string) => {
|
|
||||||
textInputWebEmitter.emit('photo-pasted', uri)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
handleKeyDown: (_, event) => {
|
handleKeyDown: (_, event) => {
|
||||||
if ((event.metaKey || event.ctrlKey) && event.code === 'Enter') {
|
if ((event.metaKey || event.ctrlKey) && event.code === 'Enter') {
|
||||||
|
|
Loading…
Reference in New Issue