 
     @_buffer.join('')
 
-  _maskedValue2: (input) ->
-    @_cursorPos = @_getSelection().begin
-    start = 0
-    diffs = jsdiff.diffChars(@state.value, input)
-
-    for diff, i in diffs
-      break if diff.added || diff.removed
-      start += diff.value.length # count?
-
-    for i in [i...diffs.length]
-      diff = diffs[i]
-
-      continue if diff.removed
-      start = @_something(start, diff.value, diff.added)
-      # start += diff.value.length
-
-    @_buffer.join('')
-
-  _something: (start, input, added) ->
-    pos = 0
-    for i in [start...@props.mask.length]
-      pattern = @_getPattern(i)
-      if pattern?
-        @_buffer[i] = @_getFormatChar(i)
-        while pos++ < input.length
-          c = input[pos - 1]
-          if pattern.test(c)
-            @_buffer[i] = c
-            break
-          else if added
-            @_cursorPos--
-
-        if pos > input.length
-          @_resetBuffer(i + 1, @props.mask.length)
-          break
-
-      else
-        @_cursorPos++ if added
-        if @_buffer[i] is input[pos]
-          pos++
-
-    i
-
 module.exports = MaskedInput


    @_cursorPos = Math.max(begin, @_firstNonMaskIdx)

  _shiftRight: (pos) ->
    c = @_getFormatChar(pos)
    for i in [pos...@props.mask.length]
      pattern = @_getPattern(i)
      if pattern?
        next = @_seekNext(i)
        t = @_buffer[i]
        @_buffer[i] = c
        if next < @props.mask.length && pattern.test(t)
          c = t
        else
          break
    true

  _callOnComplete: (value) ->
    return unless @props.onComplete?
    for i in [0...@props.mask.length]

          char

    @_cursorPos = @_firstNonMaskIdx

    # TODO: Any way we can do this in one pass?
    value: @_maskedValue(@props.value || '')

  componentDidUpdate: ->
    @_setSelection(@_cursorPos) if @_cursorPos?

  componentDidMount: ->
    if @props.mask? && @props.onChange? && @props.value? && @state.value isnt @props.value
      @props.onChange(target: {value: @state.value})

  render: ->
    if @props.mask?
      props =
        onChange: @_handleChange
        onKeyDown: @_handleKeyDown
        onFocus: @_handleFocus
        value: @state.value
    else
      props = {}

    <input {...@props} {...props} />

