 
     @props.onFocus?(e)
 
+  # TODO: rename all begin -> start
   _handleKeyDown: (e) ->
     if e.key is 'Backspace' || e.key is 'Delete'
       {begin, end} = @_getSelection()


      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()

    @_setValue value
    @_callOnComplete value

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

    originalCursorPos = @_cursorPos = @_getSelection().begin
    inputPos = i
    for bufferPos in [begin + i...@props.mask.length]
      pattern = @_getPattern(bufferPos)
      if pattern?
        @_buffer[bufferPos] = @_getFormatChar(bufferPos)
