   # historyUndo: (event) ->
 
   insertCompositionText: (event) ->
-    @composition = event.data
+    @composing = true
+    @delegate?.inputControllerWillPerformTyping()
+    @responder?.insertString(event.data)
 
   insertFromComposition: (event) ->
-    delete @composition
-    @insertReplacementText(event)
+    @composing = false
+    @delegate?.inputControllerWillPerformTyping()
+    @responder?.insertString(event.data)
 
   # insertFromDrop: (event) ->
   #

  # deleteSoftLineForward: (event) ->

  deleteWordBackward: (event) ->
    {length} = getTargetText(event)
    @delegate?.inputControllerWillPerformTyping()
    @responder?.deleteInDirection("backward", {length})

  deleteWordForward: (event) ->
    {length} = getTargetText(event)
    @delegate?.inputControllerWillPerformTyping()
    @responder?.deleteInDirection("forward", {length})

  # formatBackColor: (event) ->


    @responder?.insertLineBreak()

  insertReplacementText: (event) ->
    @delegate?.inputControllerWillPerformTyping()
    @responder?.insertString(event.dataTransfer.getData("text/plain"))

  insertText: (event) ->
    @delegate?.inputControllerWillPerformTyping()
    @responder?.insertString(event.data)

  # insertTranspose: (event) ->
  #
  # insertUnorderedList: (event) ->

updateSelectionForEvent = (event) ->
  if domRange = getDOMRangeForEvent(event)
    Trix.setDOMRange(domRange)
  else
    Trix.selectionChangeObserver.reset()

getDOMRangeForEvent = (event) ->
  if targetRanges = event.getTargetRanges?()
    if targetRanges.length
      staticRangeToRange(targetRanges[0])

staticRangeToRange = (staticRange) ->
  range = document.createRange()
  range.setStart(staticRange.startContainer, staticRange.startOffset)
  range.setEnd(staticRange.endContainer, staticRange.endOffset)
  range
