 
         when 13 # enter or return
           selection = @selection()
-          text = @textarea.val()
+          text = @element.val()
           start = text.lastIndexOf('\n', selection.start)
           end = text.indexOf('\n', selection.end)
           end = text.length if end < start

    @element.hide()
    @resize()


  focus: ->
    @textarea.focus()


  bindEvents: ->


      @pushHistory(event.keyCode)

    @element.keyup =>
      return if @previewing
      Mercury.trigger('region:update', {region: @})

    @element.mouseup =>
      return if @previewing
      @focus()
      Mercury.trigger('region:focused', {region: @})

    @previewElement.click (event) =>
      $(event.target).closest('a').attr('target', '_top') if @previewing


  content: (value = null, filterSnippets = true) ->
    if value != null
      if $.type(value) == 'string'
        @element.val(value)
      else
        @element.val(value.html)
        @selection().select(value.selection.start, value.selection.end)
    else
      return @element.val()


  togglePreview: ->
    if @previewing
      @previewElement.hide()
      @element.show()
    else
      value = @converter.makeHtml(@element.val())
      @previewElement.html(value)
      @previewElement.show()
      @element.hide()
    super


