Skip to content

Commit

Permalink
Merge pull request #426 from basecamp/fix-safari-paste-and-match-style
Browse files Browse the repository at this point in the history
Fix "Paste and Match Style" in Safari
  • Loading branch information
javan committed Jul 5, 2017
2 parents 6155eb0 + 95db10b commit d39831a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/trix/controllers/input_controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,18 @@ keyEventIsKeyboardCommand = (event) ->
if /Mac|^iP/.test(navigator.platform) then event.metaKey else event.ctrlKey

pasteEventIsCrippledSafariHTMLPaste = (event) ->
if types = event.clipboardData?.types
"text/html" not in types and ("com.apple.webarchive" in types or "com.apple.flat-rtfd" in types)
if paste = event.clipboardData
if "text/html" in paste.types
# Answer is yes if there's any possibility of Paste and Match Style in Safari,
# which is nearly impossible to detect confidently: https://bugs.webkit.org/show_bug.cgi?id=174165
mightBePasteAndMatchStyle = paste.types.some (type) ->
hasPasteboardFlavor = /^CorePasteboardFlavorType/.test(type)
hasReadableDynamicData = /^dyn\./.test(type) and paste.getData(type)
hasPasteboardFlavor or hasReadableDynamicData
else
isExternalHTMLPaste = "com.apple.webarchive" in paste.types
isExternalRichTextPaste = "com.apple.flat-rtfd" in paste.types
isExternalHTMLPaste or isExternalRichTextPaste

dataTransferIsPlainText = (dataTransfer) ->
text = dataTransfer.getData("text/plain")
Expand Down

0 comments on commit d39831a

Please sign in to comment.