   removeAttachment: (attachment) ->
     @undoManager.recordUndoEntry("Delete Attachment")
     @composition.removeAttachment(attachment)
+
+  recordFormattingUndoEntry: ->
+    locationRange = @selectionManager.getLocationRange()
+    unless locationRange?.isCollapsed()
+      @undoManager.recordUndoEntry("Formatting", context: @getLocationContext(), consolidatable: true)
+
+  recordTypingUndoEntry: ->
+    context = [@getLocationContext(), JSON.stringify(@currentAttributes)]
+    @undoManager.recordUndoEntry("Typing", context: context, consolidatable: true)

    @toolbarActions[actionName]?.perform?.call(this)

  toolbarDidToggleAttribute: (attributeName) ->
    @undoManager.recordUndoEntry("Formatting", context: @getLocationContext(), consolidatable: true)
    @composition.toggleCurrentAttribute(attributeName)
    @documentController.focus()

  toolbarDidUpdateAttribute: (attributeName, value) ->
    @undoManager.recordUndoEntry("Formatting", context: @getLocationContext(), consolidatable: true)
    @composition.setCurrentAttribute(attributeName, value)
    @documentController.focus()

  toolbarDidRemoveAttribute: (attributeName) ->
    @undoManager.recordUndoEntry("Formatting", context: @getLocationContext(), consolidatable: true)
    @composition.removeCurrentAttribute(attributeName)
    @documentController.focus()


  compositionDidChangeDocument: (document) ->
    @documentController.render()

  compositionDidChangeCurrentAttributes: (@currentAttributes) ->
    @toolbarController.updateAttributes(currentAttributes)
    @toolbarController.updateActions()

