From 158da70086aabe3b9e71e8c68e56fda98bf55a2e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 15 Dec 2018 22:45:19 +0300 Subject: [PATCH] added support for leading/trailing '/' in tag matching... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 18 +++++++++--------- ui (gen4)/imagegrid/tags.js | 20 +++++++++++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index 0a876a3e..b547a5ed 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -816,6 +816,15 @@ actions.Actions({ config: { }, + // NOTE: resetting this option will clear the last direction... + toggleShiftsAffectDirection: ['Interface/Shifts affect direction', + core.makeConfigToggler('shifts-affect-direction', + ['off', 'on'], + function(action){ + action == 'on' + && (delete this.__direction_last) })], + + // basic ribbon editing... // // NOTE: for all of these, current/ribbon image is a default... @@ -830,15 +839,6 @@ actions.Actions({ return this.current_ribbon == this.base && 'disabled' }}, function(target){ this.data.setBase(target) }], - // NOTE: resetting this option will clear the last direction... - toggleShiftsAffectDirection: ['Interface/Shifts affect direction', - core.makeConfigToggler('shifts-affect-direction', - ['off', 'on'], - function(action){ - action == 'on' - && (delete this.__direction_last) })], - - // NOTE: this does not retain direction information, handle individual // actions if that info is needed. // NOTE: to make things clean, this is triggered in action handlers diff --git a/ui (gen4)/imagegrid/tags.js b/ui (gen4)/imagegrid/tags.js index 4015a02d..884db977 100755 --- a/ui (gen4)/imagegrid/tags.js +++ b/ui (gen4)/imagegrid/tags.js @@ -306,6 +306,8 @@ var TagsPrototype = { // Query syntax: // a - tag // a/b - path, defines a directional relation between a and b + // /a - path special case, matches iff a is at path root + // a/ - path special case, matches iff a is at path base // a:b - set, defines a non-directional relation between a and b // * - tag placeholder, matches one and only one tag name // @@ -371,6 +373,9 @@ var TagsPrototype = { // match two tags... } else { + var root = /^\s*[\\\/]/.test(a) + var base = /[\\\/]\s*$/.test(a) + // normalized match... a = this.normalize(a) b = this.normalize(b) @@ -405,7 +410,13 @@ var TagsPrototype = { // tag compatibility deeper in matchSet(..)... var sa = a.split(/[\/\\]/g) var sb = b.split(/[\/\\]/g) - return sb + return ( + // fail if base/root fails... + (root && !matchSet(sa[0], sb[0]) + || (base && !matchSet(sa[sa.length-1], sb[sb.length-1]))) ? + false + // normal test... + : sb .reduce(function(a, e){ return (a[0] && (a[0] == '*' @@ -413,7 +424,7 @@ var TagsPrototype = { a.slice(1) : a }, sa) - .length == 0 + .length == 0) } }, @@ -448,6 +459,8 @@ var TagsPrototype = { match: function(a, b, cmp){ var that = this + var edge = /^\s*[\\\/]/.test(a) || /[\\\/]\s*$/.test(a) + var res = this.directMatch(...arguments) // get paths with tag... @@ -462,7 +475,8 @@ var TagsPrototype = { seen = seen || new Set() return paths(tag) .reduce(function(res, path){ - if(res == true){ + if(res == true + || (edge && !that.directMatch(a, path))){ return res }