about summary refs log tree commit diff
path: root/src/view/com/composer/text-input/TextInput.web.tsx
diff options
context:
space:
mode:
authorKuwa Lee <kuwalee1069@gmail.com>2024-06-13 15:29:51 +0800
committerGitHub <noreply@github.com>2024-06-13 15:29:51 +0800
commitecd51bc6f9f7d755eb023c3d336c21ea5b1583e5 (patch)
tree0079550833142d4842a6e7bcff4d1540bad18870 /src/view/com/composer/text-input/TextInput.web.tsx
parentbd8f0e5a1c3a49b3f134081475f90473b87111b1 (diff)
parent7faa1d9131fc28e1c0acd4b4c7b7c2bbeabc2281 (diff)
downloadvoidsky-ecd51bc6f9f7d755eb023c3d336c21ea5b1583e5.tar.zst
Merge branch 'bluesky-social:main' into zh
Diffstat (limited to 'src/view/com/composer/text-input/TextInput.web.tsx')
-rw-r--r--src/view/com/composer/text-input/TextInput.web.tsx27
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') {