isDefault supports scoped settings

This commit is contained in:
Ben Ogle
2014-10-15 14:44:16 -07:00
parent ea557ab109
commit 62c1972c95
2 changed files with 20 additions and 2 deletions

View File

@@ -99,6 +99,16 @@ describe "Config", ->
expect(atom.config.isDefault('foo.same')).toBe false
expect(atom.config.isDefault('foo.changes')).toBe false
describe "when scoped settings are used", ->
it "returns false when a scoped setting was set by the user", ->
expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe true
atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42)
expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe true
atom.config.set('.source.coffee', 'foo.bar.baz', 55)
expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe false
describe ".toggle(keyPath)", ->
it "negates the boolean value of the current key path value", ->
atom.config.set('foo.a', 1)

View File

@@ -540,8 +540,16 @@ class Config
#
# Returns a {Boolean}, `true` if the current value is the default, `false`
# otherwise.
isDefault: (keyPath) ->
not _.valueForKeyPath(@settings, keyPath)?
isDefault: (scopeSelector, keyPath) ->
if arguments.length == 1
keyPath = scopeSelector
scopeSelector = null
if scopeSelector?
settings = @scopedSettingsStore.propertiesForSourceAndSelector('user-config', scopeSelector)
not _.valueForKeyPath(settings, keyPath)?
else
not _.valueForKeyPath(@settings, keyPath)?
# Extended: Retrieve the schema for a specific key path. The schema will tell
# you what type the keyPath expects, and other metadata about the config