     if args.length is 1 then commandCompletions args[0]
     else fileNameCompletions args[0], args
   )
-  additionalText = prefix.substr(_.last(args).length)
-  controller.promptText(promptText + additionalText)
+  return if prefix == ''
+  # delete existing text so we can do case correction
+  promptText = promptText.substr(0, promptText.length - _.last(args).length)
+  controller.promptText(promptText + prefix)
 
 commandCompletions = (cmd) ->
   (name for name, handler of commands when name.substr(0, cmd.length) is cmd)

  prefix = lst[0]
  # slow, but should be fine with our small number of completions
  for word in lst
    for c, idx in prefix
      if (c isnt word[idx])
        prefix = prefix.substr(0, idx)
        break
  prefix

rs = null

# convenience functions for reading files from localStorage.
save_file = (fname, data) ->
  # inefficient but whatever
  lower = "file::#{fname.toLowerCase()}"
  for i in [0...localStorage.length] by 1
    key = localStorage.key(i)
    if key.toLowerCase() is lower
      localStorage.removeItem key
      break
  localStorage["file::#{fname}"] = data
load_file = (fname) -> localStorage["file::#{fname}"]
delete_file = (fname) -> localStorage.removeItem "file::#{fname}"

