   value = value.substring(0, @caret()) +
           String.fromCharCode(e.which) +
           value.substring(caretEnd, value.length)
-  selection = @caret()
-  selectionAtEnd = selection == @val().length
   format_.call(@, value, e)
-  if !selectionAtEnd
-    @caret(@val().length)
+  withTimeout => @caret(@val().length)
 
 formatUp_ = (e) ->
   checkForCountryChange_.call(@)

$ = jQuery

supportSelectionEnd = 'selectionEnd' of document.createElement('input')

formatForPhone_ = (phone, defaultPrefix = null) ->
  if phone.indexOf('+') != 0 and defaultPrefix

    e.preventDefault()
    @val(phone)
    if !selectionAtEnd
      withTimeout => @caret(selection)

formattedPhone_ = (phone, lastChar) ->
  if phone.indexOf('+') != 0 && @data('defaultPrefix')
