From 62c1972c9503b91ccc38ebd0db10023f5ba78e53 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Wed, 15 Oct 2014 14:44:16 -0700 Subject: [PATCH] isDefault supports scoped settings --- spec/config-spec.coffee | 10 ++++++++++ src/config.coffee | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/config-spec.coffee b/spec/config-spec.coffee index fcd2e44c3..9cfece79c 100644 --- a/spec/config-spec.coffee +++ b/spec/config-spec.coffee @@ -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) diff --git a/src/config.coffee b/src/config.coffee index 58cb465bd..69f68d70f 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -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