     @_setValue value
     @_callOnComplete value
 
-  _maskedValue: (input) ->
+  _maskedValue: (input, begin=0) ->
     for i in [0...@props.mask.length]
       break if @_buffer[i] isnt input[i]
 

  _setValue: (value) ->
    @props.onChange?(target: {value}) if value isnt @state.value
    @setState {value}
    value

  _handleFocus: (e) ->
    setTimeout =>

      {begin, end} = @_getSelection()

      if begin is end
        begin = if e.key is 'Delete' then @_seekNext(begin - 1) else @_seekPrev(begin)
        end = @_seekNext(begin)

      pattern = @_getPattern(begin)
      if pattern?.test(@_buffer[end])
        input = @state.value.substring(0, begin) + @state.value.substring(end)
        value = @_maskedValue(input)
        # input = @state.value.substring(end)
        # value = @_maskedValue(input, begin)
      else
        @_resetBuffer(begin, end)
        value = @_buffer.join('')

      @_setValue(value)

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

      e.preventDefault()

