New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty object fields not displayed in package settings #518

CheeseSucker opened this Issue May 23, 2015 · 0 comments


None yet
1 participant

CheeseSucker commented May 23, 2015

Steps to reproduce:

  1. Create a package with a config schema like this:
 module.exports =
            type: 'object'
                    type: 'string'
                    default: 'Something' 
  1. Restart atom
  2. Open settings panel and clear someSetting.prop1.
  3. Restart atom
  4. Open package settings again. No settings should be visible.

When you clear the contents of an object setting, atom stores it in config.cson as an empty object {}.

When the settings panel creates fields for editing someSetting it calls SettingsPanel::appendObject:

appendObject = (namespace, name, value) ->
  for key in _.keys(value).sort(), namespace, "#{name}.#{key}", value[key])

Since the empty object {} does not have any keys, no fields are added to the settings panel.

Possible solution:
(Optional) The first problem is that atom saves empty objects into config.cson. Instead of saving {}, remove the setting instead.

To solve the main problem, we can merge the default and current value for the setting. That way we get to keep any custom keys added to the object. Something like:

# Untested
appendObject = (namespace, name, value) ->
  defaultValue = @getDefault("#{namespace}.#{name}")
  value = $.extend({}, defaultValue, value) if defaultValue?
  for key in _.keys(value).sort(), namespace, "#{name}.#{key}", value[key])

CheeseSucker added a commit to CheeseSucker/live-doc-viewer that referenced this issue May 24, 2015

jeremyramin added a commit to jeremyramin/atom that referenced this issue Aug 23, 2015

Fix config get for objects with nested properties
Previously, the get method would return only the top keys for objects in a config schema. Now with _.deepExtends, the defaultValues are the base while any new values overwrite the defaults. This way all default values, even nested ones, appear in the result of a call to atom.config.get(packageName). This fixes atom/settings-view#386 and fixes atom/settings-view#518.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment