       html.empty().append(newContents)
 
     html.text().substr(0, caretPos)
+
+  stripNbsp: (string) ->
+    string.replace(/&nbsp;/g, '')
+
+  fixWhitespace: ->
+    html = @stripNbsp(@input.html())
+    html = html.replace(/&nbsp;/g, ' ')
+    html = html.replace(/[\s]+/g, ' ')
+    @input.html(html)
+
+  showSuccess: ->
+    @element.removeClass "invalid"
+    @element.removeClass "maybevalid"
+    @element.addClass "valid"
+    @msg.html(@SUCCESS_MSG)
+    @msg.css('color', @SUCCESS_COLOR)
+
+  showError: ->
+    @element.removeClass "valid"
+    @element.removeClass "maybevalid"
+    @element.addClass "invalid"
+    @msg.html(@ERROR_MSG)
+    @msg.css('color', @ERROR_COLOR)
+
+  showChecking: ->
+    @element.removeClass "valid"
+    @element.removeClass "invalid"
+    @element.addClass "maybevalid"
+    @msg.html(@CHECKING_MSG)
+    @msg.css('color', @NEUTRAL_COLOR)
       
 $.fn.tokenTextArea = (options, args...) ->
   @each ->

      @element.addClass "noborder"
      return

    @input = @element.find(".token-text-area-input")

    @input.attr "contenteditable", "true"
    @input.find(".token").attr("contenteditable", "false")

    @element.after('<div style="color: #b94a48; padding-left: 80px; margin-top: 10px; font-size: 12px; line-height: 16px;">Syntax error in formula.</div>')
    @errorMsg = @element.next()
    @errorMsg.hide()

    @typingTimer = null
    @resultMenu = null
    @resultList = null
    @word = null
    @range = null

    @createResultMenu()

    @registerEvents()

  registerEvents: ->

    node.contentEditable = false
    node.dataset.id = id
    node.innerHTML = name
    @range.insertNode(node)

    # Set selection range (i.e. caret position) to new token.
