Skip to content

Commit

Permalink
Directly paste ClipboardEvents in Safari (#5362)
Browse files Browse the repository at this point in the history
* Directly paste ClipboardEvents in Safari

* Add changeset
  • Loading branch information
jason0x43 committed Mar 16, 2023
1 parent e587880 commit 4399935
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-papayas-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Fix an issue where pastes in Safari wouldn't include application/x-slate-fragment data
6 changes: 5 additions & 1 deletion packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1619,9 +1619,13 @@ export const Editable = (props: EditableProps) => {
// fall back to React's `onPaste` here instead.
// COMPAT: Firefox, Chrome and Safari don't emit `beforeinput` events
// when "paste without formatting" is used, so fallback. (2020/02/20)
// COMPAT: Safari InputEvents generated by pasting won't include
// application/x-slate-fragment items, so use the
// ClipboardEvent here. (2023/03/15)
if (
!HAS_BEFORE_INPUT_SUPPORT ||
isPlainTextOnlyPaste(event.nativeEvent)
isPlainTextOnlyPaste(event.nativeEvent) ||
IS_SAFARI
) {
event.preventDefault()
ReactEditor.insertData(editor, event.clipboardData)
Expand Down

0 comments on commit 4399935

Please sign in to comment.