 
       # Red mark
       if ($(e.target).attr('id') == 'red_set')
-        # Allow: backspace, delete, tab, escape, and enter
-        if ( e.keyCode == 46 || e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 27 || e.keyCode == 13 || (e.keyCode == 65 && e.ctrlKey == true) || (e.keyCode >= 35 && e.keyCode <= 39))
-          # let it happen, don't do anything
-          return
+        # Allow: backspace, delete, escape, enter, home, end, left, right
+        if e.keyCode in [46, 8, 27, 13, 35, 36, 37, 38, 39]
+          return # let it happen, don't do anything
         else
           # Ensure that it is a number and stop the keypress
           if (e.shiftKey || (e.keyCode < 48 || e.keyCode > 57) && (e.keyCode < 96 || e.keyCode > 105 ))
-            e.preDefault()
+            e.preventDefault()
+
 
     # Button actions
     $('#add_new_button').click () =>

    $('.settings').hide()

    # Display edit, delete and update buttons
    $('#sortable div[class*=contact_container_]').hover( ((e) ->
      if $('#container_input', @).length == 0
        $('.contact_edit', @).show()
        $('.contact_delete', @).show()
        $('.contact_update', @).show()
    ), ((e) ->
      $('.contact_edit', @).hide()
      $('.contact_delete', @).hide()
      $('.contact_update', @).hide()
    ) )

    enable = 0

    $('.contact_edit').click (e) ->
      if enable == 0
        enable = 1

        # Save contact name and contact_obj
        contact_obj = $(@).parent().find('.contact_name')
        contact_id = $(e.target).parent().parent().parent().attr('id')

        # Load current settings
        $.ajax({
          url: gon.settings_path,
          data: {
            id: contact_id,
            name: contact_obj.html()
          },
          type: 'post',
          success: (data) =>
            
            contact_obj.html(SMT['edit'](data))
            $('#contact_input').focus()
            # Deselect text inside
            $('#contact_input').val($('#contact_input').val())
        })

        # Hide buttons
        $(@).hide()
        $(@).parent().find('.contact_delete').hide()
        enable = 0

    $('.contact_delete').click (e) =>
      contact_id = $(e.target).parent().parent().parent().attr('id')

      id = $(element).parent().parent().attr('id')
      name = $(element).text()

      $.post(
        gon.update_list_path,
        {
          id: id,
          name: name,
          position: i
        }
      )


  update_color: (id, red) ->
    $.post(
      gon.update_color_path,
      {
        id: id,
        red: red
      }, (data) =>
        $('#' + id).attr('class', 'contact_container_' + data["answer"])
    )


  close_settings: () =>
