mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-06 23:26:25 +03:00
Order style elements by priority
This commit is contained in:
parent
11b0a80d3d
commit
4c74b07b22
@ -32,6 +32,19 @@ describe "StylesElement", ->
|
||||
expect(element.children[initialChildCount].textContent).toBe "a {color: blue;}"
|
||||
expect(removedStyleElements).toEqual [addedStyleElements[0]]
|
||||
|
||||
it "orders style elements by priority", ->
|
||||
initialChildCount = element.children.length
|
||||
|
||||
atom.styles.addStyleSheet("a {color: red}", priority: 1)
|
||||
atom.styles.addStyleSheet("a {color: blue}", priority: 0)
|
||||
atom.styles.addStyleSheet("a {color: green}", priority: 2)
|
||||
atom.styles.addStyleSheet("a {color: yellow}", priority: 1)
|
||||
|
||||
expect(element.children[initialChildCount].textContent).toBe "a {color: blue}"
|
||||
expect(element.children[initialChildCount + 1].textContent).toBe "a {color: red}"
|
||||
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
|
||||
|
||||
|
@ -93,6 +93,7 @@ class StyleManager
|
||||
sourcePath = params?.sourcePath
|
||||
context = params?.context
|
||||
group = params?.group
|
||||
priority = params?.priority
|
||||
|
||||
if sourcePath? and styleElement = @styleElementsBySourcePath[sourcePath]
|
||||
updated = true
|
||||
@ -110,6 +111,10 @@ class StyleManager
|
||||
styleElement.group = group
|
||||
styleElement.setAttribute('group', group)
|
||||
|
||||
if priority?
|
||||
styleElement.priority = priority
|
||||
styleElement.setAttribute('priority', priority)
|
||||
|
||||
styleElement.textContent = source
|
||||
|
||||
if updated
|
||||
|
@ -53,6 +53,7 @@ class StylesElement extends HTMLElement
|
||||
styleElementClone = styleElement.cloneNode(true)
|
||||
styleElementClone.sourcePath = styleElement.sourcePath
|
||||
styleElementClone.context = styleElement.context
|
||||
styleElementClone.priority = styleElement.priority
|
||||
@styleElementClonesByOriginalElement.set(styleElement, styleElementClone)
|
||||
|
||||
group = styleElement.getAttribute('group')
|
||||
@ -62,6 +63,13 @@ class StylesElement extends HTMLElement
|
||||
insertBefore = child.nextSibling
|
||||
break
|
||||
|
||||
priority = styleElement.priority
|
||||
if priority?
|
||||
for child in @children
|
||||
if child.priority > priority
|
||||
insertBefore = child
|
||||
break
|
||||
|
||||
@insertBefore(styleElementClone, insertBefore)
|
||||
|
||||
if @context is 'atom-text-editor'
|
||||
|
Loading…
Reference in New Issue
Block a user