mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-06 23:26:25 +03:00
Handle priority in when inserting style elements in style manager
This commit is contained in:
parent
4c74b07b22
commit
94e12ee886
@ -64,3 +64,17 @@ describe "StyleManager", ->
|
||||
"a {color: green}"
|
||||
"a {color: blue}"
|
||||
]
|
||||
|
||||
describe "when a priority parameter is specified", ->
|
||||
it "inserts the style sheet based on the priority", ->
|
||||
manager.addStyleSheet("a {color: red}", priority: 1)
|
||||
manager.addStyleSheet("a {color: blue}", priority: 0)
|
||||
manager.addStyleSheet("a {color: green}", priority: 2)
|
||||
manager.addStyleSheet("a {color: yellow}", priority: 1)
|
||||
|
||||
expect(manager.getStyleElements().map (elt) -> elt.textContent).toEqual [
|
||||
"a {color: blue}"
|
||||
"a {color: red}"
|
||||
"a {color: yellow}"
|
||||
"a {color: green}"
|
||||
]
|
||||
|
@ -125,7 +125,7 @@ class StyleManager
|
||||
new Disposable => @removeStyleElement(styleElement)
|
||||
|
||||
addStyleElement: (styleElement) ->
|
||||
{sourcePath, group} = styleElement
|
||||
{sourcePath, group, priority} = styleElement
|
||||
|
||||
if group?
|
||||
for existingElement, index in @styleElements
|
||||
@ -133,6 +133,13 @@ class StyleManager
|
||||
insertIndex = index + 1
|
||||
else
|
||||
break if insertIndex?
|
||||
|
||||
if priority?
|
||||
for existingElement, index in @styleElements
|
||||
if existingElement.priority > priority
|
||||
insertIndex = index
|
||||
break
|
||||
|
||||
insertIndex ?= @styleElements.length
|
||||
|
||||
@styleElements.splice(insertIndex, 0, styleElement)
|
||||
|
Loading…
Reference in New Issue
Block a user