diff --git a/templates/modal.html b/templates/modal.html index 537d4e0..c30d12f 100644 --- a/templates/modal.html +++ b/templates/modal.html @@ -41,7 +41,7 @@

Documents toolbar settings

Apply to -
You can apply rules to set of files. Example: *.css
+
You can apply rules to set of files. Example: *.css. Use RegExp to construct complex rules.
diff --git a/viewmodels/documents.js b/viewmodels/documents.js index 889d8fa..b0c49e8 100644 --- a/viewmodels/documents.js +++ b/viewmodels/documents.js @@ -220,7 +220,8 @@ define(function(require, exports, module){ return _.find(rules, function(rule){ var query = rule.name.replace('*', ''), - currentProject; + currentProject, filterByFile, filterByRegex, + flags, pattern, regex; if (rule.project){ currentProject = self.getCurrentProjectName(); @@ -229,7 +230,18 @@ define(function(require, exports, module){ } } - return file._name.indexOf(query) >= 0; + filterByFile = file._name.indexOf(query) >= 0; + + if (query.indexOf('/') !== -1){ + flags = query.replace(/.*\/([gimy]*)$/, '$1'); + pattern = query.replace(new RegExp('^/(.*?)/'+flags+'$'), '$1'); + regex = new RegExp(pattern, flags); + filterByRegex = !!file._parentPath.match(regex) || !!file._name.match(regex); + } else { + filterByRegex = false; + } + + return filterByFile || filterByRegex; }); }