From ae857203fd2db81b073ed8fd377c415c86179899 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 15 Oct 2014 15:11:19 -0700 Subject: [PATCH] Support scoped settings in getDefault --- spec/config-spec.coffee | 13 +++++++++++++ src/config.coffee | 12 ++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index 9cfece79c..7c0a4835e 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -88,6 +88,19 @@ describe "Config", -> expect(atom.config.getDefault('foo.bar')).toEqual initialDefaultValue expect(atom.config.getDefault('foo.bar')).not.toBe initialDefaultValue + describe "when scoped settings are used", -> + it "returns the global default when no scoped default set", -> + atom.config.setDefaults("foo", bar: baz: 10) + expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 10 + + it "returns 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) + expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 42 + + atom.config.set('.source.coffee', 'foo.bar.baz', 55) + expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 42 + describe ".isDefault(keyPath)", -> it "returns true when the value of the key path is its default value", -> atom.config.setDefaults("foo", same: 1, changes: 1) diff --git a/src/config.coffee b/src/config.coffee index 69f68d70f..45daeebd2 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -530,8 +530,16 @@ class Config # * `keyPath` The {String} name of the key. # # Returns the default value. - getDefault: (keyPath) -> - defaultValue = _.valueForKeyPath(@defaultSettings, keyPath) + getDefault: (scopeSelector, keyPath) -> + if arguments.length == 1 + keyPath = scopeSelector + scopeSelector = null + + if scopeSelector? + defaultValue = @scopedSettingsStore.getPropertyValue(scopeSelector, keyPath, excludeSources: ['user-config']) + defaultValue ?= _.valueForKeyPath(@defaultSettings, keyPath) + else + defaultValue = _.valueForKeyPath(@defaultSettings, keyPath) _.deepClone(defaultValue) # Extended: Is the value at `keyPath` its default value?