mirror of
https://github.com/atom/atom.git
synced 2026-02-07 13:14:55 -05:00
Allow scoped-properties to be added/removed by name
Also: - remove "global" properties - clear scoped properties between specs
This commit is contained in:
committed by
Nathan Sobo
parent
368e10a9f5
commit
c8ec73d2f0
@@ -22,7 +22,6 @@ class Syntax
|
||||
@grammarsByFileType = {}
|
||||
@grammarsByScopeName = {}
|
||||
@grammarOverridesByPath = {}
|
||||
@globalProperties = {}
|
||||
@scopedPropertiesIndex = 0
|
||||
@scopedProperties = []
|
||||
@nullGrammar = new NullGrammar
|
||||
@@ -101,18 +100,24 @@ class Syntax
|
||||
@grammarsByScopeName[scopeName]
|
||||
|
||||
addProperties: (args...) ->
|
||||
selector = args.shift() if args.length > 1
|
||||
properties = args.shift()
|
||||
name = args.shift() if args.length > 2
|
||||
[selector, properties] = args
|
||||
|
||||
if selector
|
||||
@scopedProperties.unshift(
|
||||
selector: selector,
|
||||
properties: properties,
|
||||
specificity: Specificity(selector),
|
||||
index: @scopedPropertiesIndex++
|
||||
)
|
||||
else
|
||||
_.extend(@globalProperties, properties)
|
||||
@scopedProperties.unshift(
|
||||
name: name
|
||||
selector: selector,
|
||||
properties: properties,
|
||||
specificity: Specificity(selector),
|
||||
index: @scopedPropertiesIndex++
|
||||
)
|
||||
|
||||
removeProperties: (name) ->
|
||||
for properties in @scopedProperties.filter((properties) -> properties.name is name)
|
||||
_.remove(@scopedProperties, properties)
|
||||
|
||||
clearProperties: ->
|
||||
@scopedProperties = []
|
||||
@scopedPropertiesIndex = 0
|
||||
|
||||
getProperty: (scope, keyPath) ->
|
||||
for object in @propertiesForScope(scope, keyPath)
|
||||
@@ -128,7 +133,7 @@ class Syntax
|
||||
while element
|
||||
matchingProperties.push(@matchingPropertiesForElement(element, candidates)...)
|
||||
element = element.parentNode
|
||||
matchingProperties.concat([@globalProperties])
|
||||
matchingProperties
|
||||
|
||||
matchingPropertiesForElement: (element, candidates) ->
|
||||
matchingScopedProperties = candidates.filter ({selector}) ->
|
||||
|
||||
Reference in New Issue
Block a user