Fix resetting scoped config defaults

It would write an empty object for the parent key when there were no
other objects in the parent key.

Closes #4175
This commit is contained in:
Ben Ogle
2014-11-14 15:11:43 -08:00
parent 2266c794b4
commit 693fd43449
2 changed files with 65 additions and 5 deletions

View File

@@ -536,11 +536,13 @@ class Config
if scopeSelector?
settings = @scopedSettingsStore.propertiesForSourceAndSelector('user-config', scopeSelector)
@scopedSettingsStore.removePropertiesForSourceAndSelector('user-config', scopeSelector)
_.setValueForKeyPath(settings, keyPath, undefined)
@addScopedSettings('user-config', scopeSelector, settings, @usersScopedSettingPriority)
@save() unless @configFileHasErrors
@getDefault(scopeSelector, keyPath)
if _.valueForKeyPath(settings, keyPath)?
@scopedSettingsStore.removePropertiesForSourceAndSelector('user-config', scopeSelector)
_.setValueForKeyPath(settings, keyPath, undefined)
settings = withoutEmptyObjects(settings)
@addScopedSettings('user-config', scopeSelector, settings, @usersScopedSettingPriority) if settings?
@save() unless @configFileHasErrors
@getDefault(scopeSelector, keyPath)
else
@set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath))
@get(keyPath)
@@ -1046,3 +1048,15 @@ splitKeyPath = (keyPath) ->
startIndex = i + 1
keyPathArray.push keyPath.substr(startIndex, keyPath.length)
keyPathArray
withoutEmptyObjects = (object) ->
resultObject = undefined
if isPlainObject(object)
for key, value of object
newValue = withoutEmptyObjects(value)
if newValue?
resultObject ?= {}
resultObject[key] = newValue
else
resultObject = object
resultObject