 
     # Focus the hidden input.
     setTimeout (=>
-      @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
-        @hiddenInput.setSelectionRange 0, @hiddenInput.value.length
-      @redrawTextInput()
+      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
+          @hiddenInput.setSelectionRange 0, @hiddenInput.value.length
+        @redrawTextInput()
     ), 0
 
     # Redraw.

      on_keydown: => @shiftKeyPressed = true
      on_keyup: => @shiftKeyPressed = false

  hook 'key.enter', 0, ->
    unless @textFocus? or @shiftKeyPressed
      @setTextInputFocus null

      # Construct the block; flag the socket as handwritten
      newBlock = new model.Block(); newSocket = new model.Socket -Infinity
      newSocket.spliceIn newBlock.start
      newSocket.handwritten = true

      # Add it io our list of handwritten blocks
      @handwrittenBlocks.push newBlock

      # Seek a place near the cursor we can actually
      # put a block.
      head = @cursor.prev
      while head.type in ['newline', 'cursor', 'segmentStart', 'segmentEnd'] and head isnt @tree.start
        head = head.prev

      # Log the undo operation for this
      @addMicroUndoOperation 'CAPTURE_POINT'
      @addMicroUndoOperation new DropOperation newBlock, head

      newBlock.moveTo head #MUTATION

      @redrawMain()
      @reparseHandwrittenBlocks()
      @setTextInputFocus newSocket

    else if @textFocus? then @setTextInputFocus null; @redrawMain()

  containsCursor = (block) ->
    head = block.start

  # and might possibly do some bureaucracy in the future.
  Editor::addMicroUndoOperation = (operation) ->
    @undoStack.push operation

    # If we have blank lines at the end,
    # get rid of them
    head = @tree.end.previousVisibleToken()
    while head?.type is 'newline'
      next = head.previousVisibleToken()
      head.remove()
      head = next

    # Update the ace editor value to match,
    # but don't trigger a resize event.
