   escapeString = (str) ->
     str[0] + str[1...-1].replace(/(\'|\"|\n)/g, '\\$1') + str[str.length - 1]
 
-  # Convenince function for setting the text input
+  # Convenience function for setting the text input
   Editor::setTextInputFocus = (focus, selectionStart = null, selectionEnd = null) ->
+    if @readOnly
+      return
+
     if focus?.id of @extraMarks
       delete @extraMarks[focus?.id]
 

      @resizeBlockMode(); @redrawMain()

    else
      oldScrollTop = @aceEditor.session.getScrollTop()

      @setAceValue @getValue()

    @handwrittenBlocks = []

  hook 'keydown', 0, (event, state) ->
    if @readOnly
      return
    if event.which is ENTER_KEY
      if not @textFocus? and not event.shiftKey
        @setTextInputFocus null
