       @resize(); @redrawMain()
 
     else
-      @aceEditor.setValue @getValue(), -1
+      oldScrollTop = @aceEditor.session.getScrollTop()
+
+      @aceEditor.setValue value, -1
+      @aceEditor.resize true
+      
+      @aceEditor.session.setScrollTop oldScrollTop
 
       @iceElement.style.top = @iceElement.style.left = '-9999px'
       @aceElement.style.top = @aceElement.style.left = '0px'

  Editor::setTrimWhitespace = (trimWhitespace) ->
    @trimWhitespace = trimWhitespace

  Editor::setValue = (value) ->
    #try
      # Whitespace trimming hack to account
      # for ACE editor extra line in some applications

      @aceEditor.setValue value
      @aceEditor.resize true

      if @trimWhitespace then value = value.trim()

      newParse = coffee.parse value, wrapAtRoot: true

      if value isnt @tree.stringify()
        @addMicroUndoOperation 'CAPTURE_POINT'
      @addMicroUndoOperation new SetValueOperation @tree, newParse

      @tree = newParse; @gutterVersion = -1
      @tree.start.insert @cursor
      @redrawMain()

      return success: true

    #catch e
    #  return success: false, error: e

  Editor::getValue = -> if @currentlyUsingBlocks then @tree.stringify() else @aceEditor.getValue()


    @gutter = document.createElement 'div'
    @gutter.className = 'ice-gutter'

    @lineNumberWrapper = document.createElement 'div'
    @gutter.appendChild @lineNumberWrapper

    @gutterVersion = -1

    @lineNumberTags = {}
