Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Fixed #13072: Now Preferences objects are extended from initial value…
Browse files Browse the repository at this point in the history
…s defined in defaultPreferences.json (#13132)

* Fixed #13072: Now Preferences objects are extended from initial values defined in defaultPreferences.json

* Added test for PreferencesBase
  • Loading branch information
saurabh95 authored and swmitra committed Mar 1, 2017
1 parent 7dd7a75 commit 885b97a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ define(function (require, exports, module) {
PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", true, {
description: Strings.DESCRIPTION_CLOSE_BRACKETS
});
PreferencesManager.definePreference(CLOSE_TAGS, "object", { whenOpening: true, whenClosing: true, indentTags: [] }, {
PreferencesManager.definePreference(CLOSE_TAGS, "object", { whenOpening: true, whenClosing: true, indentTags: [], dontCloseTags: [] }, {
description: Strings.DESCRIPTION_CLOSE_TAGS,
keys: {
dontCloseTags: {
Expand Down
3 changes: 3 additions & 0 deletions src/preferences/PreferencesBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,9 @@ define(function (require, exports, module) {
var pref = this.getPreference(id),
validator = pref && pref.validator;
if (!validator || validator(result)) {
if (pref && pref.type === "object") {
result = _.extend({}, pref.initial, result);
}
return _.cloneDeep(result);
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/spec/PreferencesBase-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,32 @@ define(function (require, exports, module) {
expect(pm.get("useTabChar")).toBe(true);
expect(pm.get("tabSize")).toBe(8);
});

it("should extend Preference Objects from base", function () {
var pm = new PreferencesBase.PreferencesSystem();
pm.definePreference("closeTags", "object", {
"dontCloseTags": [],
"indentTags": [],
"whenClosing": true,
"whenOpening": true
});
var userScope = new PreferencesBase.Scope(new PreferencesBase.MemoryStorage());
pm.addScope("user", userScope);

var userLocation = {
location: {
scope: "user"
}
};
pm.set("closeTags", { "whenOpening": false }, userLocation);

expect(pm.get("closeTags")).toEqual({
"dontCloseTags": [],
"indentTags": [],
"whenClosing": true,
"whenOpening": false,
});
});

it("handles asynchronously loaded scopes", function () {
var storage1 = new PreferencesBase.MemoryStorage({
Expand Down

0 comments on commit 885b97a

Please sign in to comment.