Skip to content
Browse files

Allow `null` values in preferences

  • Loading branch information...
1 parent da5e452 commit 53f1f10fa997bd03245e8f76f50313268c588ff7 @sergeche sergeche committed
Showing with 26 additions and 8 deletions.
  1. +10 −5 javascript/preferences.js
  2. +6 −3 javascript/resolvers/cssGradient.js
  3. +10 −0 javascript/unittest/tests/cssGradient.js
View
15 javascript/preferences.js
@@ -87,7 +87,9 @@ emmet.define('preferences', function(require, _) {
v = parseInt(v + '', 10) || 0;
break;
default: // convert to string
- v += '';
+ if (v !== null) {
+ v += '';
+ }
}
preferences[k] = v;
@@ -121,10 +123,13 @@ emmet.define('preferences', function(require, _) {
*/
getArray: function(name) {
var val = this.get(name);
- if (!_.isUndefined(val)) {
- val = _.map(val.split(','), require('utils').trim);
- if (!val.length)
- val = null;
+ if (_.isUndefined(val) || val === null || val === '') {
+ return null;
+ }
+
+ val = _.map(val.split(','), require('utils').trim);
+ if (!val.length) {
+ return null;
}
return val;
View
9 javascript/resolvers/cssGradient.js
@@ -218,9 +218,12 @@ emmet.define('cssGradient', function(require, _) {
function getPrefixedNames(name) {
var prefixes = prefs.getArray('css.gradient.prefixes');
- var names = _.map(prefixes, function(p) {
- return '-' + p + '-' + name;
- });
+ var names = prefixes
+ ? _.map(prefixes, function(p) {
+ return '-' + p + '-' + name;
+ })
+ : [];
+
names.push(name);
return names;
View
10 javascript/unittest/tests/cssGradient.js
@@ -32,6 +32,16 @@ test('Expand abbreviation handler', function() {
emmet.require('actions').run('expand_abbreviation', editorStub);
equal(editorStub.getContent(), '.r{\n\tbackground-color: red;\n\tbackground-image: -webkit-gradient(linear, 0 0, 0 100%, from(red), to(black));\n\tbackground-image: -webkit-linear-gradient(red, black);\n\tbackground-image: -moz-linear-gradient(red, black);\n\tbackground-image: -o-linear-gradient(red, black);\n\tbackground-image: linear-gradient(red, black);\n}');
prefs.set('css.gradient.fallback', false);
+
+ // test gradients without prefixes
+ var prefixes = prefs.get('css.gradient.prefixes');
+ prefs.set('css.gradient.prefixes', null);
+
+ editorStub.replaceContent('.r{background:lg(red, black)$0}');
+ emmet.require('actions').run('expand_abbreviation', editorStub);
+ equal(editorStub.getContent(), '.r{background:linear-gradient(red, black);}');
+ prefs.set('css.gradient.prefixes', prefixes);
+
editorStub.setSyntax('html');
});

0 comments on commit 53f1f10

Please sign in to comment.
Something went wrong with that request. Please try again.