Skip to content

Commit

Permalink
Prevent rich-formatting paste (#4327)
Browse files Browse the repository at this point in the history
* fix: prevent rich-formatting paste

* fix: return true instead of preventDefault
  • Loading branch information
mary-ext authored Jun 13, 2024
1 parent ebd4f93 commit 247af5a
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/view/com/composer/text-input/TextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,27 @@ export const TextInput = React.forwardRef(function TextInputImpl(
attributes: {
class: modeClass,
},
handlePaste: (_, event) => {
const items = event.clipboardData?.items
handlePaste: (view, event) => {
const clipboardData = event.clipboardData

if (items === undefined) {
return
}
if (clipboardData) {
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(items, (uri: string) => {
textInputWebEmitter.emit('photo-pasted', uri)
})
getImageFromUri(clipboardData.items, (uri: string) => {
textInputWebEmitter.emit('photo-pasted', uri)
})
}
}
},
handleKeyDown: (_, event) => {
if ((event.metaKey || event.ctrlKey) && event.code === 'Enter') {
Expand Down

0 comments on commit 247af5a

Please sign in to comment.