     @observeConfigs
       'cursorType': @applyCursorType
       'primaryColor': @applyPrimaryColor
-      'primaryColorAlpha': @applyPrimaryColorAlpha
+      'primaryColorAlpha': @applyPrimaryColor
       'secondaryColor': @applySecondaryColor
-      'secondaryColorAlpha': @applySecondaryColorAlpha
+      'secondaryColorAlpha': @applySecondaryColor
       'blinkInterval': @applyBlinkInterval.bind @
       'pulseDuration': @applyPulseDuration
       'cursorThickness': @applyCursorThickness

    sheet = @getCursorStyle().sheet
    sheet.insertRule "#{selector} { #{property}: #{value}; }", sheet.cssRules.length

  getConfig: (key) ->
    atom.config.get "block-cursor.#{key}"

  setConfig: (key, value) ->
    atom.config.set "block-cursor.#{key}", value

  observeConfigs: (obj) ->
    for own key, cb of obj
      @subs.add atom.config.observe "block-cursor.#{key}", cb

module.exports = new BlockCursor()

      cursorStyle.parentNode.removeChild cursorStyle
      cursorStyle = null

  getConfig: (key) ->
    atom.config.get "block-cursor.#{key}"

  setConfig: (key, value) ->
    atom.config.set "block-cursor.#{key}", value

  observeConfigs: (obj) ->
    for own key, cb of obj
      @subs.add atom.config.observe "block-cursor.#{key}", cb

  getColor: (which) ->
    color = @getConfig "#{which}Color"
    color.alpha = @getConfig "#{which}ColorAlpha"
    color.toRGBAString()

  applyCursorType: (cursorTypeName) ->
    cursorType = cursorTypeMap[cursorTypeName] ? cursorTypeName
    workspaceView = atom.views.getView atom.workspace
    workspaceView.className = workspaceView.className.replace /block-cursor-(?:block|bordered-box|i-beam|underline)/, ''
    workspaceView.classList.add "block-cursor-#{cursorType}"

  applyPrimaryColor: =>
    color = @getColor 'primary'
    @updateStylesheet primarySelector, 'background-color', color
    @updateStylesheet primarySelector, 'border-color', color
    if 0 is @getConfig 'blinkInterval'
      @updateStylesheet secondarySelector, 'background-color', color
      @updateStylesheet secondarySelector, 'border-color', color

  applySecondaryColor: =>
    color = @getColor (if 0 is @getConfig 'blinkInterval' then 'primary' else 'secondary')
    @updateStylesheet secondarySelector, 'background-color', color
    @updateStylesheet secondarySelector, 'border-color', color

  applyBlinkInterval: do ->
    sub = null
    (interval) ->
      if interval is 0 then interval = -1 + Math.pow 2, 31
      @applySecondaryColor()
      sub?.dispose()
      sub = atom.workspace.observeTextEditors (editor) ->
        setTimeout ->
          editorPresenter = atom.views.getView(editor).component.presenter
          editorPresenter.stopBlinkingCursors true
          editorPresenter.cursorBlinkPeriod = interval
          editorPresenter.startBlinkingCursors()
        , 0
      @subs.add sub
