     workspaceView = atom.views.getView atom.workspace
     workspaceView.classList[if doFix then 'add' else 'remove'] 'block-cursor-cursor-line-fix'
 
-  getCursorStyle: ->
-    return cursorStyle if cursorStyle?
-    cursorStyle = document.createElement 'style'
-    cursorStyle.type = 'text/css'
-    document.querySelector('head atom-styles').appendChild cursorStyle
-    cursorStyle
+  updateStylesheet: do ->
+    sub = null
+    style = null
 
-  updateStylesheet: (selector, property, value) ->
-    sheet = @getCursorStyle().sheet
-    sheet.insertRule "#{selector} { #{property}: #{value}; }", sheet.cssRules.length
+    (selector, property, value) ->
+      unless sub?
+        sub = new Disposable ->
+          style.parentNode.removeChild style
+          style = null
+          sub = null
+        @subs.add sub
+      unless style?
+        style = document.createElement 'style'
+        style.type = 'text/css'
+        document.querySelector('head atom-styles').appendChild style
+      style.sheet.insertRule "#{selector} { #{property}: #{value}; }", style.sheet.cssRules.length
 
 module.exports = new BlockCursor()

'use strict'
{CompositeDisposable} = require 'atom'

class BlockCursor
  cursorStyle = null
  cursorTypeMap =
    '\u25AE - Block': 'block' # ▮
    '\u25AF - Bordered box': 'bordered-box' # ▯
    '| - I-beam': 'i-beam'
    '_ - Underline': 'underline'
  primarySelector = 'atom-text-editor::shadow .cursors .cursor'
  secondarySelector = 'atom-text-editor::shadow .cursors.blink-off .cursor'

  config:
    cursorType:

    @updateStylesheet primarySelector, 'background-color', color
    @updateStylesheet primarySelector, 'border-color', color
    # also apply to blink-off state if cursor blink is disabled
    if 0 is @getBlinkInterval()
      @updateStylesheet secondarySelector, 'background-color', color
      @updateStylesheet secondarySelector, 'border-color', color

  applySecondaryColor: =>
    # use primaryColor if cursor blink is disabled
    color = @getColor (if 0 is @getBlinkInterval() then 'primary' else 'secondary')
    @updateStylesheet secondarySelector, 'background-color', color
    @updateStylesheet secondarySelector, 'border-color', color

