diff --git a/spec/style-manager-spec.coffee b/spec/style-manager-spec.coffee index 61ddd6624..7e601bcc1 100644 --- a/spec/style-manager-spec.coffee +++ b/spec/style-manager-spec.coffee @@ -53,29 +53,6 @@ describe "StyleManager", -> expect(addEvents[0].getAttribute('source-path')).toBe '/foo/bar' expect(addEvents[0].textContent).toBe "a {color: yellow;}" - describe "when a group parameter is specified", -> - it "inserts the stylesheet at the end of any existing stylesheets for the same group", -> - manager.addStyleSheet("a {color: red}", group: 'a') - manager.addStyleSheet("a {color: blue}", group: 'b') - manager.addStyleSheet("a {color: green}", group: 'a') - - expect(manager.getStyleElements().map (elt) -> elt.textContent).toEqual [ - "a {color: red}" - "a {color: green}" - "a {color: blue}" - ] - - it "assigns priorities to 'bundled', 'theme', and 'user' groups that place them in the proper order", -> - manager.addStyleSheet("a {color: red}", group: 'user') - manager.addStyleSheet("a {color: blue}", group: 'bundled') - manager.addStyleSheet("a {color: green}", group: 'theme') - - expect(manager.getStyleElements().map (elt) -> elt.textContent).toEqual [ - "a {color: blue}" - "a {color: green}" - "a {color: red}" - ] - describe "when a priority parameter is specified", -> it "inserts the style sheet based on the priority", -> manager.addStyleSheet("a {color: red}", priority: 1) diff --git a/spec/styles-element-spec.coffee b/spec/styles-element-spec.coffee index 282cc616a..7d2fe722a 100644 --- a/spec/styles-element-spec.coffee +++ b/spec/styles-element-spec.coffee @@ -45,17 +45,6 @@ describe "StylesElement", -> expect(element.children[initialChildCount + 2].textContent).toBe "a {color: yellow}" expect(element.children[initialChildCount + 3].textContent).toBe "a {color: green}" - it "orders style elements by group", -> - initialChildCount = element.children.length - - atom.styles.addStyleSheet("a {color: red}", group: 'a') - atom.styles.addStyleSheet("a {color: blue}", group: 'b') - atom.styles.addStyleSheet("a {color: green}", group: 'a') - - expect(element.children[initialChildCount].textContent).toBe "a {color: red}" - expect(element.children[initialChildCount + 1].textContent).toBe "a {color: green}" - expect(element.children[initialChildCount + 2].textContent).toBe "a {color: blue}" - it "updates existing style nodes when style elements are updated", -> initialChildCount = element.children.length diff --git a/spec/theme-manager-spec.coffee b/spec/theme-manager-spec.coffee index 1d322f7d8..fc9624f93 100644 --- a/spec/theme-manager-spec.coffee +++ b/spec/theme-manager-spec.coffee @@ -96,8 +96,8 @@ describe "ThemeManager", -> runs -> reloadHandler.reset() - expect($('style[group=theme]')).toHaveLength 2 - expect($('style[group=theme]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/ + expect($('style[priority=1]')).toHaveLength 2 + expect($('style[priority=1]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/ atom.config.set('core.themes', ['atom-light-ui', 'atom-dark-ui']) waitsFor -> @@ -105,9 +105,9 @@ describe "ThemeManager", -> runs -> reloadHandler.reset() - expect($('style[group=theme]')).toHaveLength 2 - expect($('style[group=theme]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/ - expect($('style[group=theme]:eq(1)').attr('source-path')).toMatch /atom-light-ui/ + expect($('style[priority=1]')).toHaveLength 2 + expect($('style[priority=1]:eq(0)').attr('source-path')).toMatch /atom-dark-ui/ + expect($('style[priority=1]:eq(1)').attr('source-path')).toMatch /atom-light-ui/ atom.config.set('core.themes', []) waitsFor -> @@ -115,7 +115,7 @@ describe "ThemeManager", -> runs -> reloadHandler.reset() - expect($('style[group=theme]')).toHaveLength 2 + expect($('style[priority=1]')).toHaveLength 2 # atom-dark-ui has an directory path, the syntax one doesn't atom.config.set('core.themes', ['theme-with-index-less', 'atom-dark-ui']) @@ -123,7 +123,7 @@ describe "ThemeManager", -> reloadHandler.callCount == 1 runs -> - expect($('style[group=theme]')).toHaveLength 2 + expect($('style[priority=1]')).toHaveLength 2 importPaths = themeManager.getImportPaths() expect(importPaths.length).toBe 1 expect(importPaths[0]).toContain 'atom-dark-ui' diff --git a/src/package.coffee b/src/package.coffee index 7bb81d481..8ef160972 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -109,7 +109,7 @@ class Package getType: -> 'atom' - getStylesheetType: -> 'bundled' + getStyleSheetPriority: -> 0 load: -> @measure 'loadTime', => @@ -175,8 +175,9 @@ class Package activateStylesheets: -> return if @stylesheetsActivated - group = @getStylesheetType() @stylesheetDisposables = new CompositeDisposable + + priority = @getStyleSheetPriority() for [sourcePath, source] in @stylesheets if match = path.basename(sourcePath).match(/[^.]*\.([^.]*)\./) context = match[1] @@ -185,7 +186,7 @@ class Package else context = undefined - @stylesheetDisposables.add(atom.styles.addStyleSheet(source, {sourcePath, group, context})) + @stylesheetDisposables.add(atom.styles.addStyleSheet(source, {sourcePath, priority, context})) @stylesheetsActivated = true activateResources: -> diff --git a/src/style-manager.coffee b/src/style-manager.coffee index b18188521..c891223b9 100644 --- a/src/style-manager.coffee +++ b/src/style-manager.coffee @@ -92,12 +92,7 @@ class StyleManager addStyleSheet: (source, params) -> sourcePath = params?.sourcePath context = params?.context - group = params?.group - priority = params?.priority ? - switch group - when 'bundled' then 0 - when 'theme' then 1 - when 'user' then 2 + priority = params?.priority if sourcePath? and styleElement = @styleElementsBySourcePath[sourcePath] updated = true @@ -111,10 +106,6 @@ class StyleManager styleElement.context = context styleElement.setAttribute('context', context) - if group? - styleElement.group = group - styleElement.setAttribute('group', group) - if priority? styleElement.priority = priority styleElement.setAttribute('priority', priority) @@ -129,14 +120,7 @@ class StyleManager new Disposable => @removeStyleElement(styleElement) addStyleElement: (styleElement) -> - {sourcePath, group, priority} = styleElement - - if group? - for existingElement, index in @styleElements - if existingElement.group is group - insertIndex = index + 1 - else - break if insertIndex? + {sourcePath, priority} = styleElement if priority? for existingElement, index in @styleElements diff --git a/src/styles-element.coffee b/src/styles-element.coffee index 89673fb63..d333a2e45 100644 --- a/src/styles-element.coffee +++ b/src/styles-element.coffee @@ -56,13 +56,6 @@ class StylesElement extends HTMLElement styleElementClone.priority = styleElement.priority @styleElementClonesByOriginalElement.set(styleElement, styleElementClone) - group = styleElement.getAttribute('group') - if group? - for child in @children - if child.getAttribute('group') is group and child.nextSibling?.getAttribute('group') isnt group - insertBefore = child.nextSibling - break - priority = styleElement.priority if priority? for child in @children diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 70db13a14..0379066ca 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -219,28 +219,30 @@ class ThemeManager # # Returns a {Disposable} on which `.dispose()` can be called to remove the # required stylesheet. - requireStylesheet: (stylesheetPath, type='bundled') -> + requireStylesheet: (stylesheetPath) -> if fullPath = @resolveStylesheet(stylesheetPath) content = @loadStylesheet(fullPath) - @applyStylesheet(fullPath, content, type) + @applyStylesheet(fullPath, content) else throw new Error("Could not find a file at path '#{stylesheetPath}'") unwatchUserStylesheet: -> @userStylesheetFile?.off() @userStylesheetFile = null - @removeStylesheet(@userStylesheetPath) if @userStylesheetPath? + @userStyleSheetDisposable?.dispose() + @userStyleSheetDisposable = null loadUserStylesheet: -> @unwatchUserStylesheet() + userStylesheetPath = atom.styles.getUserStyleSheetPath() return unless fs.isFileSync(userStylesheetPath) - @userStylesheetPath = userStylesheetPath @userStylesheetFile = new File(userStylesheetPath) @userStylesheetFile.on 'contents-changed moved removed', => @loadUserStylesheet() userStylesheetContents = @loadStylesheet(userStylesheetPath, true) - @applyStylesheet(userStylesheetPath, userStylesheetContents, 'user') + + @userStyleSheetDisposable = atom.styles.addStyleSheet(userStylesheetContents, sourcePath: userStylesheetPath, priority: 2) loadBaseStylesheets: -> @requireStylesheet('../static/bootstrap') @@ -291,8 +293,8 @@ class ThemeManager removeStylesheet: (stylesheetPath) -> @styleSheetDisposablesBySourcePath[stylesheetPath]?.dispose() - applyStylesheet: (path, text, type='bundled') -> - @styleSheetDisposablesBySourcePath[path] = atom.styles.addStyleSheet(text, sourcePath: path, group: type) + applyStylesheet: (path, text) -> + @styleSheetDisposablesBySourcePath[path] = atom.styles.addStyleSheet(text, sourcePath: path) stringToId: (string) -> string.replace(/\\/g, '/') diff --git a/src/theme-package.coffee b/src/theme-package.coffee index 3c03d818f..e1b87e783 100644 --- a/src/theme-package.coffee +++ b/src/theme-package.coffee @@ -5,7 +5,7 @@ module.exports = class ThemePackage extends Package getType: -> 'theme' - getStylesheetType: -> 'theme' + getStyleSheetPriority: -> 1 enable: -> atom.config.unshiftAtKeyPath('core.themes', @name)