1
0
mirror of https://github.com/adobe/brackets.git synced 2024-11-20 18:02:54 +01:00

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

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

* Added test for PreferencesBase
This commit is contained in:
Saurabh Kathpalia 2017-03-01 13:35:52 +05:30 committed by Swagatam Mitra
parent 7dd7a75f80
commit 885b97acc4
3 changed files with 30 additions and 1 deletions

View File

@ -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: {

View File

@ -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);
}
}

View File

@ -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({