 
     existingStyleElements = @getStyleElements()
     for styleElement in styleElementsToRestore
-      unless styleElement in existingStyleElements
-        sourcePath = styleElement.getAttribute('source-path')
-        group = styleElement.getAttribute('group')
-        @addStyleElement(styleElement, {sourcePath, group})
+      @addStyleElement(styleElement) unless styleElement in existingStyleElements

      updated = true
    else
      styleElement = document.createElement('style')
      styleElement.setAttribute('source-path', sourcePath) if sourcePath?
      styleElement.setAttribute('group', group) if group?

    styleElement.textContent = source

    if updated
      @emitter.emit 'did-update-style-element', styleElement
    else
      @addStyleElement(styleElement, params)

    new Disposable => @removeStyleElement(styleElement)

  addStyleElement: (styleElement, params) ->
    sourcePath = params?.sourcePath
    group = params?.group

    if group?
      for existingElement, index in @styleElements
        if existingElement.getAttribute('group') is group
          insertIndex = index + 1
        else
          break if insertIndex?

    @styleElementsBySourcePath[sourcePath] ?= styleElement if sourcePath?
    @emitter.emit 'did-add-style-element', styleElement

  removeStyleElement: (styleElement) ->
    index = @styleElements.indexOf(styleElement)
    unless index is -1
      @styleElements.splice(index, 1)
      delete @styleElementsBySourcePath[styleElement.sourcePath] if styleElement.sourcePath?
      @emitter.emit 'did-remove-style-element', styleElement

  getSnapshot: ->
