diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 7c0a4835e..b1da6a42a 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -153,6 +153,26 @@ describe "Config", -> atom.config.restoreDefault('a.c') expect(atom.config.get('a.c')).toBeUndefined() + describe "when scoped settings are used", -> + it "restores the global default when no scoped default set", -> + atom.config.setDefaults("foo", bar: baz: 10) + atom.config.set('.source.coffee', 'foo.bar.baz', 55) + expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 55 + + atom.config.restoreDefault('.source.coffee', 'foo.bar.baz') + expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 10 + + it "restores the scoped default when a scoped default is set", -> + atom.config.setDefaults("foo", bar: baz: 10) + atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42) + atom.config.set('.source.coffee', 'foo.bar.baz', 55) + atom.config.set('.source.coffee', 'foo.bar.ok', 100) + expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 55 + + atom.config.restoreDefault('.source.coffee', 'foo.bar.baz') + expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 42 + expect(atom.config.get(['.source.coffee'], 'foo.bar.ok')).toBe 100 + describe ".pushAtKeyPath(keyPath, value)", -> it "pushes the given value to the array at the key path and updates observers", -> atom.config.set("foo.bar.baz", ["a"]) diff --git a/src/config.coffee b/src/config.coffee index 9a71ab6eb..78ed523ff 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -519,9 +519,20 @@ class Config # * `keyPath` The {String} name of the key. # # Returns the new value. - restoreDefault: (keyPath) -> - @set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath)) - @get(keyPath) + restoreDefault: (scopeSelector, keyPath) -> + if arguments.length == 1 + keyPath = scopeSelector + scopeSelector = null + + if scopeSelector? + settings = @scopedSettingsStore.propertiesForSourceAndSelector('user-config', scopeSelector) + @scopedSettingsStore.removePropertiesForSourceAndSelector('user-config', scopeSelector) + _.setValueForKeyPath(settings, keyPath, undefined) + @addScopedSettings('user-config', scopeSelector, settings) + @getDefault(scopeSelector, keyPath) + else + @set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath)) + @get(keyPath) # Extended: Get the global default value of the key path. _Please note_ that in most # cases calling this is not necessary! {::get} returns the default value when