Directly paste ClipboardEvents in Safari #5362
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR changes updates the paste handling code to always use ClipboardEvents in Safari rather than preferring InputEvents as InputEvents won't include files or data items with custom mime types.
Issue
Fixes: #4998
Example
Log the
types
of the data property passed toReactEditor.insertData
when pasting and verify that with this PR they includeapplication/x-slate-fragment
, and without this PR they don't.Ideally, if a document that has problems copying and pasting in Safari is available, such as one containing inline images, verify that content that normally has problems pastes properly with this PR.
Context
Pasting generates two events in Safari: a ClipboardEvent and an InputEvent. Currently, Slate generally ignores ClipboardEvents in Safari in favor of InputEvents, which flow through Slate's
onDOMBeforeInputHandler
. This is problematic because InputEvents generated by pasting in Safari are missing some key pieces of data: they won't include files or anapplication/x-slate-fragment
data item. ClipboardEvents do have this data.Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)