diff options
author | Mary <148872143+mary-ext@users.noreply.github.com> | 2024-06-13 09:37:49 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-13 04:37:49 +0200 |
commit | 247af5aee99ba5020b8bee9ccfa0f02bb8c4084a (patch) | |
tree | cd849b35cbbaabb100f4684280ad53729fe73035 /src | |
parent | ebd4f93b9cd2be7f5dd24f018d74d88d36eda44e (diff) | |
download | voidsky-247af5aee99ba5020b8bee9ccfa0f02bb8c4084a.tar.zst |
Prevent rich-formatting paste (#4327)
* fix: prevent rich-formatting paste * fix: return true instead of preventDefault
Diffstat (limited to 'src')
-rw-r--r-- | src/view/com/composer/text-input/TextInput.web.tsx | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/view/com/composer/text-input/TextInput.web.tsx b/src/view/com/composer/text-input/TextInput.web.tsx index 7f8dc2ed5..a91524974 100644 --- a/src/view/com/composer/text-input/TextInput.web.tsx +++ b/src/view/com/composer/text-input/TextInput.web.tsx @@ -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') { |