             line[minIndent...]
           ).join '\n'
 
+          str = str.replace /^\n*|\n*$/g, ''
+
           blocks = coffee.parse str
 
           @addMicroUndoOperation 'CAPTURE_POINT'

  class CreateSegmentOperation extends UndoOperation
    constructor: (segment) ->
      @first = segment.start.getSerializedLocation()
      @last = segment.end.getSerializedLocation()
      @lassoSelect = segment.isLassoSegment

    undo: (editor) ->

          @addMicroUndoOperation new DropOperation blocks, @cursor.previousVisibleToken()

          blocks.spliceIn @cursor
          unless blocks.end.nextVisibleToken().type in ['newline', 'indentEnd']
            blocks.end.insert new model.NewlineToken()

          @addMicroUndoOperation new DestroySegmentOperation blocks
