Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Prevent rich-formatting paste (#4327)

* fix: prevent rich-formatting paste

* fix: return true instead of preventDefault

authored by

Mary and committed by
GitHub
247af5ae ebd4f93b

+19 -8
+19 -8
src/view/com/composer/text-input/TextInput.web.tsx
··· 150 150 attributes: { 151 151 class: modeClass, 152 152 }, 153 - handlePaste: (_, event) => { 154 - const items = event.clipboardData?.items 153 + handlePaste: (view, event) => { 154 + const clipboardData = event.clipboardData 155 + 156 + if (clipboardData) { 157 + if (clipboardData.types.includes('text/html')) { 158 + // Rich-text formatting is pasted, try retrieving plain text 159 + const text = clipboardData.getData('text/plain') 160 + 161 + // `pasteText` will invoke this handler again, but `clipboardData` will be null. 162 + view.pasteText(text) 163 + 164 + // Return `true` to prevent ProseMirror's default paste behavior. 165 + return true 166 + } else { 167 + // Otherwise, try retrieving images from the clipboard 155 168 156 - if (items === undefined) { 157 - return 169 + getImageFromUri(clipboardData.items, (uri: string) => { 170 + textInputWebEmitter.emit('photo-pasted', uri) 171 + }) 172 + } 158 173 } 159 - 160 - getImageFromUri(items, (uri: string) => { 161 - textInputWebEmitter.emit('photo-pasted', uri) 162 - }) 163 174 }, 164 175 handleKeyDown: (_, event) => { 165 176 if ((event.metaKey || event.ctrlKey) && event.code === 'Enter') {