From 5ba8f580942a88e121397ae8442baf7d03691dde Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 18 Nov 2014 13:37:12 -0200 Subject: [PATCH] ensure switches are listed first: more convenient --- src/js/matrix.js | 2 +- src/js/user-rules.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/js/matrix.js b/src/js/matrix.js index 9f64f57..b28e42b 100644 --- a/src/js/matrix.js +++ b/src/js/matrix.js @@ -619,7 +619,7 @@ Matrix.prototype.toString = function() { out.push(switchName + ': ' + srcHostname + ' ' + val); } } - return out.sort().join('\n'); + return out.join('\n'); }; /******************************************************************************/ diff --git a/src/js/user-rules.js b/src/js/user-rules.js index 743bf5b..3a8fa6b 100644 --- a/src/js/user-rules.js +++ b/src/js/user-rules.js @@ -31,6 +31,19 @@ messaging.start('user-rules.js'); /******************************************************************************/ +// Switches before, rules after + +var directiveSort = function(a, b) { + var aIsSwitch = a.indexOf(':') !== -1; + var bIsSwitch = b.indexOf(':') !== -1; + if ( aIsSwitch === bIsSwitch ) { + return a.localeCompare(b); + } + return aIsSwitch ? -1 : 1; +}; + +/******************************************************************************/ + var processUserRules = function(response) { var rules, rule, i; var permanentList = []; @@ -52,7 +65,7 @@ var processUserRules = function(response) { rule = rules[i].trim(); temporaryRules[rule] = allRules[rule] = true; } - rules = Object.keys(allRules).sort(); + rules = Object.keys(allRules).sort(directiveSort); for ( i = 0; i < rules.length; i++ ) { rule = rules[i]; onLeft = permanentRules.hasOwnProperty(rule);