     next = head.prev
     head.remove()
     head = next
+
+# UNDO STACK SUPPORT
+# ================================
+
+# We must declare a few
+# fields a populate time
+hook 'populate', 0, ->
+  @undoStack = []
+  @changeEventVersion = 0
 
 # Now we hook to ctrl-z to undo.
 hook 'keydown', 0, (event, state) ->

  @dropletElement.focus()
  window.scrollTo(x, y)

# UNDO STACK SUPPORT
# ================================

# We must declare a few
# fields a populate time
hook 'populate', 0, ->
  @undoStack = []
  @changeEventVersion = 0

Editor::removeBlankLines = ->
  # If we have blank lines at the end,
  # get rid of them

  @redrawMain(); @redrawTextInput()

Editor::populateSocket = (socket, string) ->
  unless socket.stringify() is string
    lines = string.split '\n'

    unless socket.start.next is socket.end
      @spliceOut new model.List socket.start.next, socket.end.prev

    first = last = new model.TextToken lines[0]
    for line, i in lines when i > 0
      last = helper.connect new model.NewlineToken(), last
      last = helper.connect last, new model.TextToken line

    @spliceIn (new model.List(first, last)), socket.start

# Convenience hit-testing function
Editor::hitTestTextInput = (point, block) ->
