   # format: (Number index, Number length, String name, Mixed value) ->
   format: (index, length, name, value, emitEvent = true) ->
     this.doSilently( =>
-      delta = this.trackDelta( =>
-        @selection.preserve( =>
+      @selection.preserve( =>
+        delta = this.trackDelta( =>
           this.keepNormalized( =>
             @doc.format(index, length, name, value)
           )
         )
-      )
-      this.emit(ScribeEditor.events.TEXT_CHANGE, delta) if emitEvent
+        this.emit(ScribeEditor.events.TEXT_CHANGE, delta) if emitEvent
+        return delta
+      )
     )
 
   getDelta: ->


  deleteAt: (index, length, emitEvent = true) ->
    this.doSilently( =>
      delta = this.trackDelta( =>
        @selection.preserve( =>
          this.keepNormalized( =>
            @doc.deleteText(index, length)
          )
        )
      )
      this.emit(ScribeEditor.events.TEXT_CHANGE, delta) if emitEvent
    )

  doSilently: (fn) ->

            newLine = @doc.appendLine(lineNode)
            lineNode = lineNode.nextSibling
        )
        this.emit(ScribeEditor.events.TEXT_CHANGE, delta) if emitEvent and !delta.isIdentity()
        return delta
      )
    )


