       event.stopPropagation()
       return false
 
+  check_and_delete_selection: (element, woot_state) ->
+    selection = utils.get_selection_range element
+    if selection.text.length
+      # We need to delete all of the selected text.
+      delete_characters = []
+      for i in [selection.start..selection.end - 1]
+        delete_characters.push woot.generate_delete i, woot_state.string
+      for character in delete_characters
+        utils.execute_operation constants.DELETE_OPERATION, character, woot_state, element
+      utils.set_cursor element, selection.start
+      utils.send_bulk_op woot_state.events_ref, constants.DELETE_OPERATION, delete_characters
+      return true
+    return false
+
   execute_operation: (operation, woot_character, woot_state, element) ->
     if operation == constants.DELETE_OPERATION
       woot.integrate_delete woot_state.string, woot_character

        cursor = utils.get_cursor this
        woot_character = woot.generate_insert(
          cursor, k, woot_state.participant_name, woot_state.sequence_number, woot_state.string)
        woot.integrate_insert woot_state.string, woot_character
        utils.add_applied_op woot_state.applied_ops, constants.INSERT_OPERATION, woot_character
        woot_state.sequence_number += 1
        element.val woot.value(woot_state.string)
        utils.set_cursor this, cursor + 1

        utils.send_op(woot_state.events_ref, constants.INSERT_OPERATION, woot_character)

    utils = this
    element.keydown (event) ->
      if event.keyCode == 8
        selection_delete = utils.check_and_delete_selection this, woot_state
        if selection_delete
          return
        # This is the case for backspace
        cursor = utils.get_cursor this
        woot_character = woot.generate_delete cursor - 1, woot_state.string
        if woot_character
          # We have a visible character to delete
          utils.execute_operation constants.DELETE_OPERATION, woot_character, woot_state, element
          utils.set_cursor this, cursor - 1

          utils.send_op woot_state.events_ref, constants.DELETE_OPERATION, woot_character

        event.stopPropagation()
        return false
      else
        console.log event.keyCode

  bind_paste: (element, woot_state) ->
    utils = this
