 
   hook 'key.right', 0, (state, event) ->
     if not @textFocus? or
-        @hiddenInput.selectionEnd is @hiddenInput.value.length
+        @hiddenInput.selectionStart is @hiddenInput.value.length
       @moveCursorHorizontally 'right'
       event.preventDefault()
 
   hook 'key.left', 0, (state, event) ->
     if not @textFocus? or
-        @hiddenInput.selectionStart is 0
+        @hiddenInput.selectionEnd is 0
       @moveCursorHorizontally 'left'
       event.preventDefault()
 

    # Set the hidden input up to mirror the text.
    @hiddenInput.value = @textFocus.stringify()

    if selectionStart < 0 then selectionStart = @textFocus.stringify().length - selectionStart
    if selectionEnd < 0 then selectionEnd = @textFocus.stringify().length - selectionEnd

    # Focus the hidden input.
    if @textFocus?
      @hiddenInput.focus()
      if @hiddenInput.value[0] is @hiddenInput.value[@hiddenInput.value.length - 1] and
         @hiddenInput.value[0] in ['\'', '"']
        @hiddenInput.setSelectionRange 1, @hiddenInput.value.length - 1
      else

    str[0] + str[1...-1].replace(/(\'|\"|\n)/g, '\\$1') + str[str.length - 1]

  # Convenince function for setting the text input
  Editor::setTextInputFocus = (focus, selectionStart = null, selectionEnd = null) ->
    if focus?.id of @extraMarks
      delete @extraMarks[focus?.id]

