 
 keyEventIsKeyboardCommand = (event) ->
   if /Mac|^iP/.test(navigator.platform) then event.metaKey else event.ctrlKey
+
+pasteEventIsCrippledSafariHTMLPaste = (event) ->
+  if types = event.clipboardData?.types
+    "com.apple.webarchive" in types and "text/html" not in types

#= require trix/observers/mutation_observer
#= require trix/operations/file_verification_operation

{handleEvent, findClosestElementFromNode, findElementForContainerAtOffset, defer} = Trix

inputLog = Trix.Logger.get("input")


    paste: (event) ->
      paste = event.clipboardData ? event.testClipboardData
      return unless paste?

      if pasteEventIsCrippledSafariHTMLPaste(event)
        @getPastedHTMLUsingHiddenElement (html) =>
          @delegate?.inputControllerWillPasteText({paste, html})
          @responder?.insertHTML(html)
          @requestRender()

      else if html = paste.getData("text/html")
        event.preventDefault()
        @delegate?.inputControllerWillPasteText({paste, html})
        @responder?.insertHTML(html)
        @requestRender()

      else if string = paste.getData("text/plain")
        @setInputSummary(textAdded: string, didDelete: @selectionIsExpanded())
        @delegate?.inputControllerWillPasteText({paste, string})
        @responder?.insertString(string)

      else if "Files" in paste.types
        if file = paste.items?[0]?.getAsFile?()
          if not file.name and extension = extensionForFile(file)
            file.name = "pasted-file-#{++pastedFileCount}.#{extension}"
          @delegate?.inputControllerWillAttachFiles()
          @responder?.insertFile(file)
          @requestRender()

      else
        event.preventDefault()

    compositionstart: (event) ->
      @mutationObserver.stop()
